Thursday, February 27, 2014

socket server side can not catch exceptions: recvfrom fail: ETIMEDOUT


A Mobile: open wifi hotspot, do socket server side
B Phone: make socket client-side, connect the phone socket server
AAfter the socket connection is established, both sides are calling read blocking;
A cell phone turned off or shut down B Mobile hotspot wifi: client-side can catch the exception recvfrom fail: ETIMEDOUT, server not capture

Is this what the reason, there is no way for the server side also caught exception?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Server-side code:
Thread a = new Thread () {
public void run () {
ServerSocket socket;
try {
socket = new ServerSocket (40000);
Socket client = socket.accept ();
if (null! = client) {
InputStream in = client.getInputStream ();
BufferedReader reader = new BufferedReader (
new InputStreamReader (in));
reader.readLine ();
}
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}
};
a.start ();

Client code:
Thread a = new Thread () {
public void run () {
try {
Socket server = new Socket ();
SocketAddress socketAddress = new InetSocketAddress ("192.168.43.1",
40000);
server.connect (socketAddress);
InputStream in = server.getInputStream ();
BufferedReader reader = new BufferedReader (new InputStreamReader (in));
reader.readLine ();
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}
};
a.start ();

Reply:
Just tried to open a hot machine as the client, in this case off the network, socket server can catch exceptions recvfrom fail: ETIMEDOUT

The question now relatively clear, as the hot end of this exception can not be caught, someone know the reason, please return it, online, thank you

No comments:

Post a Comment