Re: Sending and Receiving over socket
- From: "Lew Pitcher" <lpitcher@xxxxxxxxxxxx>
- Date: 14 Apr 2007 20:48:41 -0700
On Apr 14, 9:12 pm, "Jack" <accpac...@xxxxxxxxxxx> wrote:
Hi Everyone,
I have a question. If I have a client and a server machine and on my
client machine I execute this code:
send (socketfd, &rHeader, 2 * sizeof(int)), 0);
and on my server machine I execute:
recv (socketfd, &buffer, 2 * sizeof*(int)), 0);
can I be sure that the full buffer will be sent and received when
these two are executed.
Yes and no.
The send() will schedule transmission of the data you've provided. It
is up to the sockets, tcp/ip and ethernet/ppp layers to determine
whether the data will consist of one packet or multiple packets, and
schedule the transmission of the packets.
On the recv() side, recv() will only return the data that has been
received and dequeued. This /may/ be less than the amount you sent.
You will have to recv() until you have received all the data.
If not is there a way to make sure that these two I done.
On the sending side, you can close the tcp connection (assuming a
stream socket). This will force the scheduling (in due time) of the
transmission of the remaining data. However, as you will have closed
the connection, you won't be able to send any more data across that
connection. And, assuming that you did not perform a half-close, you
won't be able to receive any data at the sending side either.
I guess I am looking for a function like fflush() but for sockets.
AFAIK, there aint no such thing
HTH
--
Lew
Thanks
.
- Follow-Ups:
- Re: Sending and Receiving over socket
- From: Beej Jorgensen
- Re: Sending and Receiving over socket
- References:
- Sending and Receiving over socket
- From: Jack
- Sending and Receiving over socket
- Prev by Date: Sending and Receiving over socket
- Next by Date: Freeing an array of pointer
- Previous by thread: Sending and Receiving over socket
- Next by thread: Re: Sending and Receiving over socket
- Index(es):
Relevant Pages
|