I am developing a mobile application for Android. There I create a socket and transfer data between Android mobile phones and windows (which run on a PC, laptop). I am using Android 2.3
Samsung Mobile Galaxy Testing
PCs and mobile phones are connected via USB titration.
Correct data transfer.
But one of the problems is in the middle of the application, which is canceled by disconnecting the mobile USB drive from the system, and then I throw an exception.
But sometimes this does not happen to any exception, it just waits, Socket is also not closed waiting for data to be read
So please send default socket timeout in android
My code examples are below
Socket socket=null; DataOutputStream dos=null; OutputStream os=null; InputStream is=null; DataInputStream dis=null; try { Log.i(tagName, "b4 creating socket"); socket=new Socket(this.getIpAddress(),this.getPort_number()); is=socket.getInputStream(); dos=new DataOutputStream(os); dis=new DataInputStream(is); } catch(UnknownHostException unknown_ex) { Log.i(tagName, "Exception host unknown : "+unknown_ex.toString()); unknown_ex.printStackTrace(); } catch(IOException ioe_ex) { Log.i(tagName, "ioe Exception : "+ioe_ex.toString()); ioe_ex.printStackTrace(); } catch(Exception ex) { Log.i(tagName, "Exception : "+ex.toString()); ex.printStackTrace(); } if(dos!=null) { try { dos.close(); } catch(Exception ex) { } } if(dis!=null) { try { dis.close(); } catch(Exception ex){} } if(socket!=null) { try { socket.close(); } catch(Exception ex) { } } socket=null;dos=null;dis=null; Log.i(tagName, "MySocketConnection.connectMe() - end");
When i use code
Socket.getSoTimeout()
Then it returns 0.
Please give everyone your ideas.
java android android-networking sockets socket-timeout-exception
SIVAKUMAR.J
source share