On 8/8/06, Nico Heinze <[EMAIL PROTECTED]> wrote:
> --- In [email protected], "Indika Bandara" <[EMAIL PROTECTED]>
> wrote:
[...]
> > do i have to send starting/ending sequences to mark the
> > start/end of packets.
> >
> > for example.
> > after creating socket and calling connect();
> >
> > i call at client
> > write(10 bytes);
> > write(15);
> >
> > then at server i call
> > read(10);
> > read(15);
> >
> > will i get what i send? will the server not read any garbage?
>
> Indika,
>
> don't worry, TCP/IP will handle these issues for you. But -as usual
> with read() and write()- you should always check that the amount of
> bytes you receive during one read() call equals the amount of bytes
> you expect.
> So, in order to create a fairly reliable protocol, you should always
> encapsulate the data (be it a protocol command or a single block of
> data or whatever) in a packet that you can check for errors yourself;
> for example, use the first four bytes (in a clearly defined order!) to
> transfer the actual length of a block of data; after these four bytes
> only send the actual data to transfer. So you will have to implement
> two read()s:

http://tangentsoft.net/wskfaq/intermediate.html#packetscheme details
the two common ways of implementing a stream over a packet based
protocol, and references the example at
http://tangentsoft.net/wskfaq/examples/packetize.html

-- 
PJH

Into motorcycles? Need parts? Try www.gissit.com to contact lots of
motorcycle breakers - free to use (UK based at the moment)


To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/c-prog/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to