Re: Suggestions for custom application-layer protocol?

From: Grant Edwards (grante_at_visi.com)
Date: 05/26/05


Date: Thu, 26 May 2005 18:22:18 -0000

On 2005-05-26, Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:

>:For simplicity of implementation, I'd recommend implementing a message
>:layer over the TCP socket - something as simple as a two byte binary header
>:to indicate the length of the message to follow.
>
>:This means you can then read a whole message - text based or otherwise,
>:and the process it accordingly. You don't need to mess about with parsing
>:lines and stuff like that.
>
> You still need to "mess about" if your data might not fit in a single
> packet.

And even if it does.

> Recall that when you read() from a socket you are not certain
> to get all of the data unless the data length is no greater
> than your system's atomicity limits [PIPE_BUF]. The POSIX
> minimum value for PIPE_BUF is 512 -- so in the general case a
> write() of more than 512 bytes may require multiple read()
> statements.

The data may have passed through a bridge or router that may
have broken it up even further. It's a bad idea to make any
assumptions about any correspondance between write() and read()
calls on a TCP connection. It's just a byte stream: you
oughtn't depend on any sort of datagram behavior whatsoever.

A 500 byte "message" may have been sent using a single call to
write(), but the receiver had better be prepared to call read()
anywhere from 1 to 500 times.

-- 
Grant Edwards                   grante             Yow!  Two with FLUFFO,
                                  at               hold th' BEETS...side of
                               visi.com            SOYETTES!


Relevant Pages

  • Re: Suggestions for custom application-layer protocol?
    ... You don't need to mess about with parsing ... oughtn't depend on any sort of datagram behavior whatsoever. ...
    (comp.os.linux.embedded)
  • Changing an XCode (default|setting|preference|something}
    ... But if I've got a bazillion or three source files to mess ... I start to thinking about what the boilerplate in 836 new files says, ... it looks as though it's coming from some sort ... find the stationery, or the preference file, or whatever it is I need to ...
    (comp.sys.mac.programmer.help)
  • Getting VB to sort numbers?
    ... "Number parsing in VB" ... I have just shown 2 two locations on a 4 hour time span, ... I could be pointed towards a good tutorial that deals with this sort ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Ping: Hackintoshers.
    ... It becomes a manageable mess. ... It doesn't let me organise it _at all_. ... I can't drag dtuff around, ... Right click, sort by name (oh and it stays like that, not sure I could ...
    (uk.comp.sys.mac)
  • Re: FC4 - KVM mouse needing reset
    ... Have to admit its kind of a mess... ... this worked - sort of. ... >> I don't know how to refresh the mouse from the commandline, ...
    (Fedora)