UDP协议模拟服务端
public static void main(String[] args) throws IOException {
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf,buf.length);
DatagramSocket ds = new DatagramSocket(9999);
while (true){
ds.receive(dp);
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
DataInputStream dis = new DataInputStream(bais);
System.out.println(dis.readLong());
}
}
本文详细介绍了如何使用Java语言实现UDP协议的服务器端模拟,包括创建DatagramSocket、接收数据包、读取数据流并打印长整型值的过程。
1779

被折叠的 条评论
为什么被折叠?



