Home > Archive > Unix Programming > January 2008 > how to flush the socket
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to flush the socket
|
|
| Mountain 2008-01-20, 8:12 am |
| hi everyone
i am using tcp protocol
while receiving bytes from server in the client , i am not able to
receive the hole bytes,what i have sended in the server side.
In the second receive i am receiving the last bytes of first send
byes and some of second send bytes
how i will receive the correct no of bytes at correct time
is there is any mechanism to flush the socket,where i can use before
receiving next data.
thanks in advance
| |
| Barry Margolin 2008-01-20, 7:16 pm |
| In article
<69b333a9-956b-4f2d-970f-43db23993029@z17g2000hsg.googlegroups.com>,
Mountain <jg.girish4u@gmail.com> wrote:
> hi everyone
> i am using tcp protocol
> while receiving bytes from server in the client , i am not able to
> receive the hole bytes,what i have sended in the server side.
> In the second receive i am receiving the last bytes of first send
> byes and some of second send bytes
> how i will receive the correct no of bytes at correct time
> is there is any mechanism to flush the socket,where i can use before
> receiving next data.
> thanks in advance
TCP is a byte stream protocol, it has no notion of message boundaries.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| catastrofus@gmail.com 2008-01-21, 4:33 am |
| On Jan 20, 11:43 am, Mountain <jg.giris...@gmail.com> wrote:
> hi everyone
> i am using tcp protocol
> while receiving bytes from server in the client , i am not able to
> receive the hole bytes,what i have sended in the server side.
> In the second receive i am receiving the last bytes of first send
> byes and some of second send bytes
> how i will receive the correct no of bytes at correct time
> is there is any mechanism to flush the socket,where i can use before
> receiving next data.
> thanks in advance
Use MSG_WAITALL in recv?
Gert.
| |
| Tim White 2008-01-21, 7:28 pm |
| Since TCP is a byte stream protocol you need to know how many bytes are
include in a message either by appending a header to the front of the
message or pre-defining a message size (not exactly practical). When
you receive the message at the destination, first read the header for
the number of bytes then loop on a read until the entire message is
read. You should limit the number of loops in case you have an error
somewhere.
Tim
catastrofus@gmail.com wrote:
> On Jan 20, 11:43 am, Mountain <jg.giris...@gmail.com> wrote:
>
> Use MSG_WAITALL in recv?
>
> Gert.
|
|
|
|
|