Galaxy Tab 10.1 and DatagramSocket problem

While working with sockets on Android you may face the problem with InvalidArgumentException thrown when you try to create a new instance of DatagramSocket:

InetSocketAddress bindInetAddr = new InetSocketAddress(bindAddr, bindPort);
DatagramSocket ssdpUniSock = new DatagramSocket(bindInetAddr);

The second line causes InvalidArgumentException error. Fortunately, the solution exists and is quite simple. Instead of creating an instance of DatagramSocket, you can obtain in from DatagramChannel and then bind an address:

DatagramChannel channel = DatagramChannel.open();
DatagramSocket ssdpUniSock = channel.socket();
InetSocketAddress bindInetAddr = new InetSocketAddress(bindAddr, bindPort);
ssdpUniSock.bind(bindInetAddr);

Voila, done!