Help: asyncore/asynchat and terminator string

D

David Hirschfield

I'm implementing a relatively simple inter-application communication
system that uses asyncore/asynchat to send messages back and forth.

The messages are prefixed by a length value and terminator string, to
signal that a message is incoming, and an integer value specifying the
size of the message, followed by the message data.

My question is: how can I produce a short terminator string that won't
show up (or has an extremely small chance of showing up) in the binary
data that I send as messages?

Frankly, I'm not so sure this is even an important question, but is
nagging me. If my communication is a kind of state machine:

sender: sends message length value, followed by terminator string,
followed by message data
receiver: waiting for terminator string via set_terminator(<terminator
string>)
continually save what comes in via collect_incoming_data()
receiver: when sender's message arrives, found_terminator() is called
pull message length from previously received data
set terminator to be the length of the message via
set_terminator(<message length>)
receiver: collect_incoming_data() collects the message data
receiver: found_terminator() called when full message length is read,
receiver goes back to waiting for message terminator string

I hope I explained that clearly enough.

The only time I can conceive that the system will get confused by
finding a terminator string in the binary data of the message is if
something goes haywire and I end up looking for a terminator string when
the other side is sending the message data. What gotchas do I need to
look out for here? I'm not a networking person, so I'm relying on the
underlying libraries to be stable and just let me handle the high-level
stuff here. This isn't going to be used in a malicious environment, the
only thing I have to contend with is network hiccups...nobody is
actively going to try and break this system.

Any advice/help would be appreciated,
-Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top