socket通信---模拟服务端(UDP篇)

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());
}
}

你可能感兴趣的:(socket,UDP,模拟服务端)