 |
|
 |
|
|
 |
Protocols to exchange messages via a socket |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
03-12-07 12:22 PM
the_edge123.nospam@club-internet.fr wrote:
> Hello,
>
> I'm not sure I'm at the right group for this question.
> I want to send a binary message over a socket and I'm wondering which
> protocols are best suitable:
>
> 1) <separator><msg in hexa printable characters><separator>
> This solution works but doubles the message length :-(
>
> 2) <msg length><raw msg>
> The issue is that we're not sure to be at the beginning of the msg.
> Can I receive correctly the next message if I close and re-open the
> socket in case of a decoding error ?
As long as your <msg length> is right, you don't have to close and
re-open the socket if the message is bad.
If your message length takes up more than one byte, be careful that the
reader and writer of the socket agree on its endianness, i.e. that they
agree which byte of the length is the most significant.
Robert
>
> Thanks in advance,
> Fabien
>
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
03-12-07 06:23 PM
On Mon, 12 Mar 2007 03:20:32 -0700, the_edge123.nospam wrote:
> Hello,
>
> I'm not sure I'm at the right group for this question. I want to send a
> binary message over a socket and I'm wondering which protocols are best
> suitable:
>
> 1) <separator><msg in hexa printable characters><separator> This
> solution works but doubles the message length :-(
How does it double the message length?
> 2) <msg length><raw msg>
> The issue is that we're not sure to be at the beginning of the msg. Can
> I receive correctly the next message if I close and re-open the socket
> in case of a decoding error ?
I'd highly recommend net strings:
http://cr.yp.to/proto/netstrings.txt
...just because multiple applications have implemented them, and there
isn't going to be any gain in doing something different. They have a
length and a "separator" ... although I'd recommend dropping the
connection on a netstring parse error, although it would be possible to
search for the next netstring.
--
James Antill -- james@and.org
http://www.and.org/and-httpd/ -- $2,000 security guarantee
http://www.and.org/vstr/
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
03-12-07 06:23 PM
James Antill <james-netnews@and.org> writes:
> On Mon, 12 Mar 2007 03:20:32 -0700, the_edge123.nospam wrote:
>
> How does it double the message length?
If you transform the original binary values into hexadecimal
representation, each nibble becomes a hex digit.
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
03-13-07 12:20 AM
the_edge123.nospam@club-internet.fr wrote in
news:1173708146.840736.307610@n33g2000cwc.googlegroups.com:
> I think I will use <separator><msg length><raw msg><separator>
> to be able to recover in burst-sending mode if msg length is
> corrupted.
As long as <separator> cannot occur in <raw msg>, even if there is
corruption.
MV
--
Do not send e-mail to the above address. I do not read e-mail sent
there.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
03-13-07 12:20 AM
On Mon, 12 Mar 2007 03:20:32 -0700, the_edge123.nospam wrote:
> Hello,
>
> I'm not sure I'm at the right group for this question.
> I want to send a binary message over a socket and I'm wondering which
> protocols are best suitable:
>
> 1) <separator><msg in hexa printable characters><separator>
> This solution works but doubles the message length :-(
>
> 2) <msg length><raw msg>
> The issue is that we're not sure to be at the beginning of the msg.
> Can I receive correctly the next message if I close and re-open the
> socket in case of a decoding error ?
>
If all you're doing is writing messages across the wire, then no.
You cannot be sure how many messages were lost on the wire behind any
corrupted messages, but which were assumed "sent" by the sender. Also,
assuming TCP the atomicity of writes isn't guaranteed. You could have lost
1/2 a packet in transit.
You have to implement some sort of message accounting, for example
using windows and some retry protocol. To get an idea of how to approach
things (aside from reading the TCP RFC's), read up on this implementation:
http://airhook.ofb.net/
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
03-13-07 06:29 AM
In article <1173694832.757185.244440@p10g2000cwp.googlegroups.com>,
the_edge123.nospam@club-internet.fr wrote:
> Hello,
>
> I'm not sure I'm at the right group for this question.
> I want to send a binary message over a socket and I'm wondering which
> protocols are best suitable:
Rather than designing your own, why not use an existing library like
XDR? And if you also use the RPC library it will handle lots of other
aspects of the protocol, such as automatic retransmission if you're
using UDP.
--
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 ***
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
03-13-07 06:29 AM
On Mar 12, 3:20 am, the_edge123.nos...@club-internet.fr wrote:
> I'm not sure I'm at the right group for this question.
> I want to send a binary message over a socket and I'm wondering which
> protocols are best suitable:
> 1) <separator><msg in hexa printable characters><separator>
> This solution works but doubles the message length :-(
You can use base 64 instead of hex if you prefer. That will increase
the message length by much less (about a third).
Alternatively, you can pick a character that appears only rarely in
your message, and use it as a separator. For example, of 0x55 appears
only rarely in your message, you can use 0x55 followed by 0x00 as your
message separator and 0x55 followed by 0xff to indicate a real 0x55 in
your message. This will only double a message if it consists of all
0x55's. (If you want to get fancy, you can use 0x55 followed by the
number of consecutive 0xff's in the real message, so two or more
consecutive 0x55's don't double in size. Use 0x55 0x00 as a
separator.)
You only need to reserve one character as a separator.
> 2) <msg length><raw msg>
> The issue is that we're not sure to be at the beginning of the msg.
> Can I receive correctly the next message if I close and re-open the
> socket in case of a decoding error ?
What kind of socket is this? If it's TCP, this is not an issue. Just
always start a new connection with the length of a message. If
something goes wrong somehow, close and re-open the connection and
know you'll start at the beginning of a message.
There are very few real-world cases where resynchronization is a real
issue. Broadcast is one of them; is that what you're doing?
DS
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: Protocols to exchange messages via a socket |
 |
 |
|
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 10:04 PM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|