0
votes

WiBro, which is used as a server module and client Nexus Galaxy ICS. Both machines are 3g UDP communication. The server will return only the received data has been implemented.

dSocket.send (sendPacket) is a smooth communication. However, we have a problem. dSocket.receive (recvPacket) does not receive the data.

The server sends the packet is wrong? If the client receives the packet is wrong? The server sends data but, telecom equipment is taken to preserve the situation?

When only sending a packet, the client has not a problem. but after receive code implementation, the client has a problem.

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;
        }
    }

}
1
Your 'connected' variable is misnamed. You are never really connected in UDP. - user207421
I knew, but udp does not maintain a connection. Am I not correct? - reinhard.lee
Exactly, so you can't have a 'connected' state either. So it is misnamed. - user207421
Do you control the server code? Are you sure the server receives and process the command datagram? Does receive() timeout after 5 seconds? - Peter Tran

1 Answers

0
votes

The server sends the packet is wrong?

Could be. Hard to say without seeing it. It should send the reply back to the IP:port embedded in the incoming datagram. Easiest way to do that is to reuse it, just change the data.

the client receives the packet is wrong?

It looks OK.

The server sends data but, telecom equipment is taken to preserve the situation?

I don't know what this means.