I'm writing an Android app that connects to an authentication server to retrieve the IP address and port of another Android device running a separate server program. The authentication server sends the correct connection information when the request is sent. The problem is when the client device attempts to connect to the Android server. The client gets the correct information and closes the previous connections successfully, but hangs when it attempts to create the new connections. No exceptions are thrown, but the UI is unresponsive and the device eventually says the app isn't responding. I have an emulator acting as the client device and an actual phone acting as the server.
Here is the part of the client code that it gets stuck on:
Log.i("Socket", "About to open a new socket");
socketChannel = SocketChannel.open(new InetSocketAddress(ip, port));
socketChannel.configureBlocking(false);
socketChannel.register(selector, SelectionKey.OP_READ);
Log.i("Socket", "New socket created and registered");
ip is a String
containing the IP address of the server. port is the port number of the server. I have the two calls to Log.i()
to find where the program hangs. The first call executes, but the second doesn't. Is there any reason that this code segment would cause the app to freeze?
I can post more of my code if needed, but I'm pretty sure the problem is in the segment provided above.