WiBro,用作服务器模块和客户端 Nexus Galaxy ICS。两台机器都是3g UDP通讯。服务器将只返回已执行接收到的数据。
dSocket.send(sendPacket) 是一种流畅的通信。但是,我们有一个问题。dSocket.receive (recvPacket) 不接收数据。
服务器发送的数据包是错误的?如果客户端接收到的数据包是错误的?服务器发送数据但是,电信设备被采取保存的情况?
当只发送一个数据包时,客户端没有问题。但是在接收代码执行后,客户端出现了问题。
private class ClientThread implements Runnable{
@SuppressWarnings("finally")
@Override
public void run() {
// TODO Auto-generated method stub
DatagramSocket dSocket = null;
try{
InetAddress serverAddr = InetAddress.getByName(serverIpAddress.toString());
Log.d(TAG, "Connecting");
Log.d(TAG, "IP :::: " + serverAddr.toString());
dSocket = new DatagramSocket(SERVERPORT);
dSocket.setSoTimeout(5000);
byte[] arr_RecvPacket = new byte[1024];
connected = true;
while(connected){
try{
Log.d(TAG, "Sending Command :::: ( " + String.valueOf(i));
String strPacket = "Hey Server ( " + String.valueOf(i);
byte[] arr_Packet = strPacket.getBytes();
sendPacket = new DatagramPacket(arr_Packet, arr_Packet.length, serverAddr, SERVERPORT);
dSocket.send(sendPacket);
Log.d(TAG, "C:Send");
i++;
Log.d(TAG, "C:Make Recv Packet....");
recvPacket = new DatagramPacket(arr_RecvPacket, arr_RecvPacket.length);
Log.d(TAG, "C:Recving...");
dSocket.receive(recvPacket);
handler.sendEmptyMessage(0x01);
Thread.sleep(4000);
}catch(Exception e){
e.printStackTrace();
Log.d(TAG, "S:Error");
}
}
Log.d(TAG, "S:DataSocket close");
dSocket.close();
}catch(Exception e){
Log.d(TAG, "C:Error");
e.printStackTrace();
connected = false;
}finally{
connected = false;
if(dSocket != null){
dSocket.close();
}
return;
}
}
}