/*run()方法实现文字通信的接收数据功能*/
public void run(){
try{
DatagramSocket socket=new DatagramSocket(5000);//创建数据报套接字
while(true){
socket.receive(dp);//接收数据;
jTextArea1.append("\n数据来自:"+"
"+dp.getAddress());
String received=new String(dp.getData(),0,dp.getLength());
jTextArea1.append("\n接收到的数据:"+"
"+ received+"\n");
}
}
catch(Exception ioe){
jTextArea1.append(ioe.toString()+"\n");
ioe.printStackTrace();
}
}