Application Using Socket Freezes When It Tries To Connect To Server
I am doing application which send some data from mobile phone to PC. Im using socket to do it. When the server is online it works, but when I try to connect with wrong ip/port or s
Solution 1:
You can set the connection timeout. You have to use different constructor of Socket
class. Insead of:
Socketsocket=newSocket(serverAddr, s_port);
use:
Socketsocket=newSocket();
socket.connect(newInetSocketAddress(serverAddr, s_port), 5000);
In case of timeout an exception is thrown.
Solution 2:
Perhaps you didn't set a timeout
connection
so it's "0
" by default which means that it will never timeout , so you can set the timeout to 1 minute it won't freeze for more than one minute .
Post a Comment for "Application Using Socket Freezes When It Tries To Connect To Server"