Help: asyncore/asynchat and terminator string

Discussion in 'Python' started by David Hirschfield, Jan 16, 2007.

  1. 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

    --
    Presenting:
    mediocre nebula.
    David Hirschfield, Jan 16, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Welsh

    asyncore asynchat

    Michael Welsh, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    515
    Michael Welsh
    Jul 15, 2003
  2. F.G.Testa

    asyncore/asynchat

    F.G.Testa, Nov 14, 2003, in forum: Python
    Replies:
    4
    Views:
    426
    MetalOne
    Nov 17, 2003
  3. Joshua Moore-Oliva

    asyncore, asynchat and threads

    Joshua Moore-Oliva, Aug 4, 2004, in forum: Python
    Replies:
    4
    Views:
    1,054
    Joshua Moore-Oliva
    Aug 4, 2004
  4. Z. Kotzer
    Replies:
    0
    Views:
    342
    Z. Kotzer
    Mar 15, 2006
  5. dbtouch
    Replies:
    32
    Views:
    3,233
    Jerry Coffin
    Mar 8, 2009
Loading...

Share This Page