I wanted to know how to flush the socket streams while doing socket programming in C. I tried all the options- setting TCP_NODELAY using the following code-
setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
Note: all the flag and sockfd are declared correctly.
I used this function both before send() and after send() but it did not make any difference.
Also someone had suggested to use shutdown() after each send() but that works only for one instance. When I use it to send some text again, it doesn’t work- actually the connection gets closed after I use shutdown().
shutdown(sockfd, SHUT_WR);
Can someone help in this regard?
I wanted to added that- the server is a Java socket and the client is a C socket. The C socket implements the JVMTI interface and sends the information to the Java socket.
You might want to read The ultimate SO_LINGER page, or: why is my tcp not reliable, which I think applies to your situation.
Edit:
Calling
send()on a TCP socket multiple times is not that uncommon 🙂 It’s normal usage, I mean. You probably have issues on the server side, where server expects certain number of bytes and blocks waiting for it.As far as I know JVM TI does not dictate any over-the-wire protocol, so you’ll have to come up with your own. Define structure of the record the client sends and server expects, put data length in there if size varies. You might also implement some application-level acknowledgement from server back to client.