📄 dgram.java
字号:
/*
* 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);
//构造数据报包,用来将长度为 length 的包发送到指定主机上的指定端口号。
return new DatagramPacket(buf, buf.length, destIA, destPort);
}
public static String toString(DatagramPacket p) {
return new String(p.getData(), 0, p.getLength());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -