application dying at port creation
My application crashes when trying to open a connection in the following code. I believe it is because the port is being used, but im not sure. Let me know if you see anything wrong with the code below or have any idea what the problem may be. The application makes it to
Log.v("connectdevice", "after ipadress");
SOME times it will make it past that point. But is rarely. Also, there is no exception caught.
Thanks in advance!
try {
Log.v("connectdevice", "inside make connection");
InetAddress host = InetAddress.getByName("192.168.201.开发者_如何转开发65");
Log.v("connectdevice", "after ipadress");
socket = new Socket(host.getHostName(), 7777);
Log.v("connectdevice", "after socket");
connected = true;
} catch (UnknownHostException e) {
connected = false;
e.printStackTrace();
} catch (IOException e) {
connected = false;
e.printStackTrace();
}
Use
Log.e("Error", "exception", e);
This way you can see the Exceptions on Logcat
[Posted by ssfn]
That is strange. I only see that new Socket(host.getHostName(), 7777) is a little sub-optimal, as this might (?) include a reverse DNS lookup. Socket will accept InetAddress. Just use Socket(host, 7777).
If ssfn comes by and puts his answer here, i am going to accept it asap. Until then, this is the accepted answer.
精彩评论