L
lightning
I have some sockets connected to the server when I init a socket pool,
after using one socket, I would put the socket back into the pool for
the next time to use, but sometimes the server goes out and it close
some of my sockets.
How do I know that?
It seems that isConnected() , isClosed(),.... etc cannot tell me the
real fact. Only when I read from the inputstream I get -1. Is this the
only way? What's the best practise in this situation?
Now the solution of mine is:
1, setSoTimeout(1)
2, wrap the socket 's inputstream to become a PushbackInputStream
3, read one byte from the inputstream,if the return value is not -1 or
read() throw a timeoutexception , it is cool, otherwise I need to
purge the socket
I need advices....
after using one socket, I would put the socket back into the pool for
the next time to use, but sometimes the server goes out and it close
some of my sockets.
How do I know that?
It seems that isConnected() , isClosed(),.... etc cannot tell me the
real fact. Only when I read from the inputstream I get -1. Is this the
only way? What's the best practise in this situation?
Now the solution of mine is:
1, setSoTimeout(1)
2, wrap the socket 's inputstream to become a PushbackInputStream
3, read one byte from the inputstream,if the return value is not -1 or
read() throw a timeoutexception , it is cool, otherwise I need to
purge the socket
I need advices....