Terminating InputStream.read() while using Sockets

Hi

I am using Sockets for a TCP communication between a client and a server. First, the client sends some data, then the server
responds. The client can send ANY data, so I cannot define a termination signal like 255 or \n or such.
I am using read() on the InputStream of the Socket to read the data the client sends. When read
returns -1 I process the data and reply.

Now my problem is, that the server blocks in read() and I am not sure how to make it return -1, or how the
client can terminate the stream.

I found the method shutdownOutput, which sends a termination signal to the server and then read returns -1.
So when I use a Java Server and a Java Client, I use shutdown to signal that all data is send and it works.

But now I have to receive data from clients written in Delphi and C, and somehow I cant find ways to terminate the
server InputStream without closing the whole socket.

Did you ever build a TCP communication with other programming languages and how do you
organise request, response and end of transmission?

-JAW

when I send messages to clients or server, I put message length first and then receiver reads as long as needed and then process the message. I think this should be easily done with other programming languages as well.

close the socket and read will return, i think

whats wrong with closing the whole socket? I beleave tcp-sockets are even called stream sockets. when the stream is closed the assosiated socket is closed, sounds reasonable to me. thats also why accept() returns a new socket.

if you know no semantics on the data recieved how are you gonna process it then? If there are semantics then extend those.

I wonder if you need a term signal send back if your using tcp it should raise hell wenn it can’t backup it’s own claims of reliable inorder(it didn’t recieve an ack within time out). you don’t need a higher level ‘ack’/term signal. A resend at most but that would be an exotic case since it does checks on that too.

I think I’m missing the point or something.