how to ensure the data is sent via a tcp socket before reading from it

Issue

This Content is from Stack Overflow. Question asked by wangz

I write a simple client ,server program in c ,linux ,my client will send a short message to to server ,then it calls recv(fd,…) immediately to read data from the same socket ,but I found the the data is not sent to server , only I quit the client ,then data is sent to server ,I think it is because the socket is closed then data is sent , but after some search , find there is no way to flush socket , and TCP_NODELAY doesn’t have the flush effect.

Is there a way to solve this ,currently I am using tcp socket .



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?