asynchat network send problems

A

Andreas R.

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|initiate_send|219]
[C:\Python24\lib\asyncore.py|send|332]
[C:\Python24\lib\socket.py|_dummy|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
http://svn.gna.org/viewcvs/openrts/trunk/openrts/client/networkclient.py?rev=39&view=markup

Network client is found here:
http://svn.gna.org/viewcvs/openrts/trunk/openrts/server/clienthandler.py?rev=41&view=markup

This is the sequence for sending data:

1. In clienthandler.py 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_terminator() in
networkclient.py

4. In the found_terminator() 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
http://svn.gna.org/daily/openrts-snapshot.tar.gz


Thanks anyone for the help,

- Andreas R.
www.openrts.org
 
S

Scott David Daniels

Andreas said:
4. In the found_terminator() 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.

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

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top