java - DataInputStream readByte blocked / hanging -


I am looking for a server code that threads to handle every incoming connection. The problem is that for some reason on a group of thread, data inputs created from the socket are hanging on the reading-blaat and not to throw an exception. The timeout is set to 60 seconds, so I'm not sure what the next step is with it.

  socket.setSoTimeout (timeout); SocketInputStream = socket.getInputStream (); Byte connectionopts = socketDataInputStream.readByte ();    

You have indicated in a comment that you SocketException . If this is the case, you need to capture SocketTimeoutException instead, for example, this code output will be out of the timeout! If you wait for Telnet port 3434 and 3 seconds:

  try {ServerSocket ss = new ServerSocket (3434); Socket socket = ss.accept (); Socket.setSoTimeout (3000); Inputstream socket incutice = socket.getInputStream (); DataInstream data inputstream = new dataInputStream (Socket Instestream); DataInputStream.readByte (); } Hold (SocketTimeoutException e) {System.out.println ("timed!"); }    

Comments