2
votes

I am experiencing a problem on Android when sending SIP packets over UDP to the port 5060 using a device instead of the emulator. The exception is:

java.net.SocketException: sendto failed: EPERM(Opereation not permitted)

On some devices such as the Galaxy Nexus the same code works bot on other devices such as the Asus Transformer TF101 and the Galaxy Tab 2 I am experiencing these problems. I have the required permission android.permission.INTERNET. When sending the same SIP packet over another port (say 9876) the packet is sent successfully. Even when sending other content over port 5060 (not SIP packets) the packet is still sent successfully. It seems that the combination of SIP packets over port 5060 are not being permitted on some devices. I created a test program to replicate this problem:

try
{
    DatagramSocket clientSocket = new DatagramSocket();
    InetAddress IPAddress = InetAddress.getByName("10.111.110.6");
    byte[] sendData = new byte[1024];
    byte[] receiveData = new byte[1024];
    String sentence = "Register sip ...";
    sendData = sentence.getBytes();
    DatagramPacket sendPacket = new DatagramPacket(sendData, 
        sendData.length, IPAddress, 5060);
    clientSocket.send(sendPacket);
    DatagramPacket receivePacket = new DatagramPacket(receiveData, 
        receiveData.length);
    clientSocket.receive(receivePacket);
    int x = receivePacket.getLength();
    String modifiedSentence = new String(receivePacket.getData(), 0, x);
    ds_tv.setText("FROM SERVER:" + modifiedSentence + " Length: "+ x);
    clientSocket.close();
}
catch (Exception e)
{
    Log.e("Test", e.getMessage());
    ds_tv.setText(e.getMessage());
}

This test program consists just of a single button and the above code is called in its onClick() event. The packet consisting of the String sentence which contains the SIP registration packet is not sent over port 5060. If I modify the port, the packet is sent successfully and even if I modify the content of the string sentence. However if I send the SIP registration packet over port 5060 the SocketException occurs. I do not know what could be the problem or how to go about solving such an issue.

1
Any firewall or security software that could be in the way?plmaheu
Are you using the above IP address in a real the device? This IP would be unreacheble unless you were connected to a private class C network. Most likely your device network address is a class B starting with 192.168...Luis
The device is on a Class C network. I will investigate whether there is any security however there should not be any in the way.frans1989
There is no firewall in the way. I also installed a packet sniffer on the device and found out that the packet is not even being sent from the device. I can't understand what might be the problem since on some devices and on the emulator the same code within the same environment works.frans1989

1 Answers

1
votes

The problem has been solved and the error was being caused from the payload of the SIP packet. The CSeq value in the SIP packet was being set to 0 initially. Instead it had to start from 1.