Asyncore Help?

P

Paul Kozik

I am working on the networking code for a small Multiplayer RPG I'm
working on. I currently have some basic code using threads, but it
seems like asyncore would be far better suited for my needs. However,
I have trouble finding a solid example for what I need. Python.org and
other sites provide simple examples, but they appear more intended for
servers that simply send one peice of data to the client.

I want to have a server program that is willing to accept commands
sent from the client, and repeatedly wait for data and respond.
Maintaining a long term connection until the client is done playing.

Besides this I am also stuck with dealing with TCP data streams. I can
receive and send the data (using threads, not yet with asynocore), but
I am unsure how to deal with the streamlike nature of TCP (and would
prefer to use TCP over UDP). I would like to have it so that the
client sends the server a command (such as update position), and then
the data, and have the server update that information on its side
accordingly.

While basic socket work was rather easy to deal with, this has proved
significantly more difficult. Are there any good free sources for
information on Asyncore, and dealing with TCP?
 
E

Erik Max Francis

Paul said:
While basic socket work was rather easy to deal with, this has proved
significantly more difficult. Are there any good free sources for
information on Asyncore, and dealing with TCP?

You haven't said specifically what you're having a problem with. The
more general name for asyncore/asynchat is Medusa, and there are some
resources with more examples available here:

http://www.nightmare.com/medusa/
http://www.amk.ca/python/code/medusa.html
 
N

Nick Craig-Wood

Erik Max Francis said:
You haven't said specifically what you're having a problem with. The
more general name for asyncore/asynchat is Medusa, and there are some
resources with more examples available here:

http://www.nightmare.com/medusa/
http://www.amk.ca/python/code/medusa.html

There is also twisted of course if we are talking about async
networking libraries.

http://twistedmatrix.com/trac/

The learning curve of twisted is rather brutal, but it will do
everything you want and a whole lot more! I haven't tried Medusa, but
I've done several things with twisted. It takes a bit of getting your
head round but you'll be impressed with the speed.
 
B

Bjoern Schliessmann

J

Josiah Carlson

Paul said:
I am working on the networking code for a small Multiplayer RPG I'm
working on. I currently have some basic code using threads, but it
seems like asyncore would be far better suited for my needs. However,
I have trouble finding a solid example for what I need. Python.org and
other sites provide simple examples, but they appear more intended for
servers that simply send one peice of data to the client.

Here is a sample that combines asyncore/asynchat, wxPython, and optional
threads:
http://thread.gmane.org/gmane.comp.python.wxpython/46915/focus=47326

You can pull out the async subclasses and use them as a general Python
object transfer mechanism.

If you have specific asyncore/asynchat questions, email me directly and
I will try to help you.

- Josiah
 
B

billiejoex

I have trouble finding a solid example for what I need. Python.org and
other sites provide simple examples, but they appear more intended for
servers that simply send one peice of data to the client.

Not a big deal. asynchat / asyncore are pretty easy-to-learn
frameworks. Under the hoods they are extremely simpler if compared to
Twisted.
You shouldn't have problems in learning how the things works in a
couple of days.
Try to take a look at:
http://effbot.org/zone/asyncore-ftp-client.htm
http://effbot.org/librarybook/asynchat.htm
Besides this I am also stuck with dealing with TCP data streams. I can
receive and send the data (using threads, not yet with asynocore), but
I am unsure how to deal with the streamlike nature of TCP (and would
prefer to use TCP over UDP).

If you really need speed UDP could be a better choice.
While basic socket work was rather easy to deal with, this has proved
significantly more difficult.

Developing a bug-less network application by using the basic socket
module instead of an high-level framework like asyncore it's surely a
lot harder.
Again: asyncore is really simple: it's just a matter of understanding
the event-based approach that's very different from the thread-based
one.
 
B

billiejoex

I have trouble finding a solid example for what I need. Python.org and
other sites provide simple examples, but they appear more intended for
servers that simply send one peice of data to the client.

Not a big deal. asynchat / asyncore are pretty easy-to-learn
frameworks. Under the hoods they are extremely simpler if compared to
Twisted.
You shouldn't have problems in learning how the things works in a
couple of days.
Try to take a look at:
http://effbot.org/zone/asyncore-ftp-client.htm
http://effbot.org/librarybook/asynchat.htm
Besides this I am also stuck with dealing with TCP data streams. I can
receive and send the data (using threads, not yet with asynocore), but
I am unsure how to deal with the streamlike nature of TCP (and would
prefer to use TCP over UDP).

If you really need speed UDP could be a better choice.
While basic socket work was rather easy to deal with, this has proved
significantly more difficult.

Developing a bug-less network application by using the basic socket
module instead of an high-level framework like asyncore it's surely a
lot harder.
Again: asyncore is really simple: it's just a matter of understanding
the event-based approach that's very different from the thread-based
one.
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top