My client is writen in java. The server is written in C.
When the client read from the server, the read function return -1.
I kown in java if the outputstream closed before the socket closed, java client will receive -1. but when in C, when the java client will receive -1?
JAVA CASE:
OutputStream out = socket.getOutputStream();
out.write(buf);
out.close();
out.write(otherbuf);
In this case the when the client call read() it will return -1.
If server is writen in c, when the java client will return -1??
Thanks.
What language the server is written in is irrelevant. It could be written in anything, the client does not know and should not care (in general).
A
readwill return-1when it reaches the end of stream, as documented. The end of stream happens when the other side closed that side of the (TCP) socket.(On the C side, assuming a POSIX system, the socket can be closed either with the
close(2)system call, or with theshutdown(2)system call. The later allows the program to only close one “side” of the connection, i.e. close the write side but keep the read side open.closeshuts both sides down.)