日期:2014-05-20 浏览次数:20628 次
class Udpreceive{
public static void main(String[] args) throws Exception {
DatagramSocket dgs=new DatagramSocket(10000);
byte[] bt=new byte[1024];
DatagramPacket dgp=new DatagramPacket(bt, bt.length);
dgs.receive(dgp);
String ip=dgp.getAddress().getHostAddress();
String data=new String(dgp.getData(),0,dgp.getLength());
int port=dgp.getPort();
System.out.println("ip:"+ip+"-------data:"+data+"----port:"+port);
}
}