I'm attempting to connect two separate applications via a TCP/IP socket. In this case neither of the applications is running as a "client" of the other, it would be easier to describe them as two separate servers who need to communicate with each other.
To receive the data I'm using the InputStream.Read()
function and once it receives a value of -1
it should stop processing. However, now the problem is that if another set of data comes along the InputStream
is already at the End of S开发者_运维问答tream (EOS
) and so all new data being sent is discarded or ignored. The only way I have found to fix this problem is that once the End of Stream has been reached I close the socket and reopen it which I think might be handled better some other way.
How can I reset the InputStream so that it is ready for the next set of data that may come along?
You are getting EOS when reading from a TCP/IP Socket because the other end has closed the write side of its socket. Once this happens, the TCP/IP protocol provides no way to "unclose" the connection.
If you don't want to have to open a new connection, you need an application protocol on top of the TCP/IP transport protocol that allows you to signify the end of each logical dataset ... without doing a close.
精彩评论