I have a server-client application and I’ve hit a weird speed bump with “login failure codes” of sorts.
What I want to do is send the code that describes the login’s validity and close the OutputStream if necessary.
The problem with this is that the socket is closed before the client can read the response, which is leading to seemingly random and cryptic failures.
Is there a way, aside from using a setSoLinger() (etc.), to check that the last byte (or more) that was written has been read by the client?
Thanks.
In Java, the only way for your server application to know that the client has received something is to include this property in the protocol: the client must send some kind of message stating that it received the data (maybe with some kind of checksum if you want), and the server must then wait for this message. Only then it can be sure of anything.
There’s no other reliable way to be sure that the other endpoint received some data: no
.close(), no.flush(), nothing will guarantee reception by the other endpoint.