100分求解,为什么客户端之间UDP不能互相发送数据
服务器端已经和客户端能够成功通信,但客户端之间发送UDP数据的时候为何不行:
简略程序如下:
public class A implements Runnable{
//实现发送UDP数据的函数
public void send(usrname){
.....
String s="ONLINE"+usrname;//online做为关键字
for(int i=0;i<onlineips.size();i++){//从客户端得到的在线用户IP
String ips=onlineips.get(i).toString().trim();
sendPacket=new DatagramPacket(data,s.length(),
InetAddress.getByName(ips),sendPort);
sendSocket.send(sendPacket);
}
public void run(){//run函数实现监听
receivePacket=new DatagramPacket(array,array.length);
receiveSocket.receive(receivePacket);
byte[] data=receivePacket.getData();
String received=new String(data,0,data.length);
if(received.substring(0,6).equals("ONLINE")){//测试是否发送成功
System.out.println("Received information from others");
}
public void MainWin(...){
........
Thread thread=new thread(this);
thread.start();
A.send("client");
}
}
====================================================
大致上简单的就是这样,大家帮忙看看问题出在哪里?谢谢