Results 1 to 3 of 3
Hello all,
Its been a long time since my last visit. After nearly 2 years I get to work on my favourite distro again and here I am with a ...
- 07-14-2011 #1Just Joined!
- Join Date
- Mar 2008
- Location
- Chennai, India
- Posts
- 26
TCP send and recv sync problem.
Hello all,
Its been a long time since my last visit. After nearly 2 years I get to work on my favourite distro again and here I am with a question:
I am implementing a client server application for a product in C. This application is similar to the HTTP client server application. The server opens a socket and listens for a request from client. the client connects to the server and makes a request. Server does a recv(/* Request */) and client does a send(/* Request */). If client wants to send some additional data, its does another send(/* Data */) and server does a recv(/* Data */) to get this data.
My problem is that the client's send(Request) and send (data) are entertained by the server's recv(Request) and recv(data) goes on an infinite wait.
My recv() call is as follows
My send() call is as followsCode:unsigned char mesg[20000]; bytes_read = recv(socket, (void *)mesg, sizeof(mesg), 0);
How can I make recv to break after the first send is served. The recv call has to be blocking but should break after receiving an EOF or a null character(end of string).Code:unsigned char data[20000] = "this is a test string.\n"; res = send(skt, data, req->data_len, 0);
Any suggestions would be greatly appreciated.
Cheers!
Sarma
- 07-14-2011 #2Just Joined!
- Join Date
- Mar 2008
- Location
- Chennai, India
- Posts
- 26
Flush Socket -- is there a way???
Is there a way to flush the buffered data on a socket before writing to it? I learnt that TCP generally buffers data to check overhead. For short packet transactions, we have to set TCP_NODELAY option to disable TCP buffering. I tried this but to no avail.
Is there a way to flush the socket before next write?
- 07-15-2011 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You need to set the server to do non-blocking reads, otherwise it will wait until all 2000 bytes are received. So, usually, the server will issue a select() call so it can know when there is data to read, and then it will issue a recv() call on the socket(s) that have data to read.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote