?? dgram.java
字號(hào):
/*
* Dgram.java
*
* Created on 2007年7月13日, 下午3:05
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
import java.net.*;
public class Dgram {
public static DatagramPacket toDatagram(String s, InetAddress destIA,
int destPort) {
byte buf[]=s.trim().getBytes();
//byte[] buf = new byte[s.length()];
//s.getBytes(0, s.length(), buf, 0);
//構(gòu)造數(shù)據(jù)報(bào)包,用來(lái)將長(zhǎng)度為 length 的包發(fā)送到指定主機(jī)上的指定端口號(hào)。
return new DatagramPacket(buf, buf.length, destIA, destPort);
}
public static String toString(DatagramPacket p) {
return new String(p.getData(), 0, p.getLength());
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -