package cn
.itcast_01
;
import java
.io
.IOException
;
import java
.net
.DatagramPacket
;
import java
.net
.DatagramSocket
;
import java
.net
.InetAddress
;
public class ReceiveDome {
public static void main(String
[] args
) throws IOException
{
DatagramSocket ds
= new DatagramSocket(10086);
byte[] bys
= new byte[1024];
int length
= bys
.length
;
DatagramPacket dp
= new DatagramPacket(bys
,length
);
ds
.receive(dp
);
InetAddress address
= dp
.getAddress();
String ip
= address
.getHostAddress();
byte[] bys2
= dp
.getData();
int length2
= dp
.getLength();
String s
= new String(bys2
,0,length2
);
System
.out
.println(s
+"---"+ip
);
ds
.close();
}
}
转载请注明原文地址: https://lol.8miu.com/read-25135.html