Recving data - whan it is finished?

18 views
Skip to first unread message

Gall Anonim

unread,
Mar 6, 2014, 2:17:47 PM3/6/14
to lib...@googlegroups.com
Hi,
that is me again :)

I use small loop to receive data:

while(bRec2 < BUFFER_SIZE){
    bRec2=bRec;
    bRec+=sock.Recv(data,bRec2);

How data transfer is send to client?
One big package which will be returned by sock.Recv ? If not,  this function gets small packages ? which needs to be combined(connected?) ?
Is there something like EOF which informs me that transfer was finished?

Imagine you don't know how much data will be send to you.

Thank you,
Rafal

Ivan Gagis

unread,
Mar 11, 2014, 4:54:41 AM3/11/14
to lib...@googlegroups.com
Hi Rafal,

No, not a one big package. Network transmits data in its own way, depending on many factors, like load of the network, transmission speed etc. And surely if you sent some data in one Send() call that does not mean that you receive the same data in one Recv() on the other end. It may come in several calls to Recv().

There is no any EOF-like thing. It is up to you to develop a protocol which will allow you to determine when a finalized portion of data is received that you can start handling it. There are many approaches to that. The most simple is that before sending a package of data you send the size of that package, so on the other end after receiving that size they will know how many bytes to receive for the package. The other approach is to use text-based protocol, like XML or JSON, so by receiving portions of it and parsing piece by piece you will know when the main, for example, JSON object is ended and can be handled on the receiving end.

I hope you got the idea.

Br,
Ivan
--
You received this message because you are subscribed to the Google Groups "libting" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libting+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Gall Anonim

unread,
Mar 12, 2014, 6:10:07 PM3/12/14
to lib...@googlegroups.com
Thank you Ivan
:)
Reply all
Reply to author
Forward
0 new messages