Configure Java socket to fail on disconnect?

I have a listening port on my server that I connect to using the Java class and interface Socket, i.e.

Socket mySocket = new Socket(host,port);

Then I grab OutputStream, decorate PrintWriterin autorun mode, and I laugh - except that the listening port closes. Then i get

tcp4       0      0  *.9999                 *.*                    LISTEN
tcp        0      0  127.0.0.1.45737        127.0.0.1.9999         CLOSE_WAIT

and I canโ€™t detect the problem in the program - I tried to use the method isConnected()on the socket, but I donโ€™t seem to know that the connection is closed.

I want to know about the problem the next time I start and write to Socket so that I can try to reconnect and report the problem.

Any tips please?

Thank you all

+3
source share
3 answers

-?

isOutputShutdown() , ?

SocketWatcher, Thread Socket, SocketClosedException.

0

TCP , " reset" IOException. - , p, . .

0

. , . , .

-2

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


All Articles