为什么while外,的ds.colse()会报错,,,
只要在DatagramSocket ds=new DatagramSocket(10000);语句后加
while(true){}后面的语句就出错,为什么?
public static void udpReceive() throws Exception{
DatagramSocket ds=new DatagramSocket(10000);
while(true){
byte[] buf=new byte[1024];
DatagramPacket dp=new DatagramPacket(buf,buf.length);
ds.receive(dp);
String ip=dp.getAddress().getHostAddress();
String data=new String(dp.getData(),0,dp.getLength());
int port=dp.getPort();
System.out.println(ip+"::"+data+"::"+port);
}
//System.out.println("dd");
//ds.close();
} |