Java / groovy socket write timeout

I have a simple poorly organized server (written in Groovy)

ServerSocket ss = new ServerSocket(8889);
Socket s = ss.accept()
Thread.sleep(1000000)

And the client from whom I want to get a timeout (since the server does not consume it)

Socket s = new Socket("192.168.0.106", 8889)
s.setSoTimeout(100);
s.getOutputStream.write( new byte[1000000] );

However, this client is blocked forever. How to make a client break?

THANKS!!

+3
source share
3 answers

You can call the client in its own thread and block the lock / wait (timeout) on it to return. You can use the Future object to get the return value if Socket is successful.

I believe that the SO_TIMEOUT parameter for Socket only calls read (..) calls from the socket, not a write.

SocketChannel ( Stream) , . .

+3

- TCP, . TCP , , . , TCP/IP -. , tcpdump ( wireshark, :) ACK , . Java (, , nio), ACK poll/select.

+1

, , , .

0

Source: https://habr.com/ru/post/1710283/


All Articles