Debug调试在socket.send(packet);出错,求解。。。。
class ClientClass extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
try {
InetAddress serverAddress=InetAddress.getByName("255.255.255.255");
int messageCount=0;
DatagramSocket socket=new DatagramSocket();
byte[] buffer=localIpAddress.getBytes();
DatagramPacket packet=new DatagramPacket(buffer,buffer.length,serverAddress,4567);
while (true) {
try {
socket.send(packet);
} catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
}
System.out.println("Send Data:" + new String(packet.getData()));
Toast.makeText(MainActivity.this, "数据已发送!", Toast.LENGTH_SHORT).show();
try {
Thread.sleep(1000);
} catch (Exception e) {
// TODO: handle exception
}
messageCount++;
buffer = (localIpAddress + messageCount).getBytes();
packet.setData(buffer,0,buffer.length);
}
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(MainActivity.this, "数据未能发送!", Toast.LENGTH_SHORT).show();
}
super.run();
}
}
------解决方案--------------------
代码没看出问题 换ip 改端口 多试试
------解决方案--------------------
255.255.255.255你这个server地址对吗?哪有地址是这样的
------解决方案--------------------
难道必须用255.255.255.255,有这种IP地址????client怎么把包发送到服务器端呢?
建议你换成server的ip
------解决方案--------------------
貌似地址不能这样滴,一般都是最后一个字段是255,前面跟局域网地址一样。建议下个网络调试助手,先测试下,再看是不是代码的问题