asynchat network send problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas R.

    #1

    asynchat network send problems

    Hello,
    I'm using Python's asynchat module for network support in a Python-based
    game, and I run into two problems, both of which occur at random times.
    Most of the time, the network sending and receiving is perfect, but
    about 1 out of 10 times, it fails with one of these errors:

    -- Problem 1. When sending data, I sometimes the following exception:

    Handler connected 127.0.0.1:1242 at 0x2977800> (socket.error:( 9, 'Bad
    file descriptor') [C:\Python24\lib \asynchat.py|in itiate_send|219]
    [C:\Python24\lib \asyncore.py|se nd|332]
    [C:\Python24\lib \socket.py|_dum my|144])

    -- Problem 2. Receiving data on the client is not always the same size
    as the data which is sent from the server.

    Network server is found here


    Network client is found here:


    This is the sequence for sending data:

    1. In clienthandler.p y the method send_to_client( ) is called with
    whatever data should be sent to the client.

    2. send_to_client( ) compresses the data, and passes it to the push()
    method of asynchat.

    3. Client receives the data, and called found_terminato r() in
    networkclient.p y

    4. In the found_terminato r() method, the data is attempted to be
    uncompressed, but it failes, since the received data does not have the
    same size as the data which is sent. Sometimes, the difference in size
    is often 512 between client and server, when running len(packet) on the
    *compressed* packed. The len() of a large packet is usually about 64969.

    Complete source code is available at



    Thanks anyone for the help,

    - Andreas R.

  • Scott David Daniels

    #2
    Re: asynchat network send problems

    Andreas R. wrote:[color=blue]
    > 4. In the found_terminato r() method, the data is attempted to be
    > uncompressed, but it failes, since the received data does not have the
    > same size as the data which is sent. Sometimes, the difference in size
    > is often 512 between client and server, when running len(packet) on the
    > *compressed* packed. The len() of a large packet is usually about 64969.[/color]

    Just a guess, but do you know "send" and "receive" are not guaranteed to
    send all bytes or receive all bytes? The network itself is allowed to
    re-pack packets at any point in the path, and delays may happen at any
    packet boundary (including those boundaries created by the network).
    You need to do something like "sendall" and your receiver needs to know
    when it needs to wait for more data (as a matter of protocol design).

    --
    -Scott David Daniels
    scott.daniels@a cm.org

    Comment

    Working...