views:

144

answers:

1

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 Stream (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?

+2  A: 

You are getting EOS when reading from a TCP/IP Socket, that is 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.

Stephen C
Figures it wouldn't be so simple. Well since I have no control of the other end as to it closing its write side I'll just have to go back to checking for EOS and then performing a close and open again. Thank you.
JRSofty