473,897 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asyncore Help?

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?
May 14 '07 #1
7 2660
Paul Kozik wrote:
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

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
I used to walk around / Like nothing could happen to me
-- TLC
May 14 '07 #2
Erik Max Francis <ma*@alcyone.co mwrote:
Paul Kozik wrote:
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
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.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
May 14 '07 #3

On May 14, 2007, at 4:30 AM, Nick Craig-Wood wrote:
The learning curve of twisted is rather brutal
:-)

May 14 '07 #4
Nick Craig-Wood wrote:
http://twistedmatrix.com/trac/

The learning curve of twisted is rather brutal,
NACK, the tutorial is -- IMHO -- rather easy if you are used to
writing Python code and doing asynchronous programming.

<http://twistedmatrix.com/projects/co...ntation/howto/
tutorial/index.html>
but it will do everything you want and a whole lot more!
That's true. More Twisted, less work (and less headache). IMHO.

Regards,
Björn

--
BOFH excuse #242:

Software uses US measurements, but the OS is in metric...

May 14 '07 #5
Paul Kozik wrote:
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.p...15/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
May 17 '07 #6
On 14 Mag, 06:51, "Paul Kozik" <zyk...@gmail.c omwrote:
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.

May 17 '07 #7
On 14 Mag, 06:51, "Paul Kozik" <zyk...@gmail.c omwrote:
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.

May 17 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2708
by: Michael Welsh | last post by:
In order to learn sockets in Python I am trying to write a simple group chat server and client. I need a little nudge, please. My question contains some GUI but only as decoration. The root question is asyncore / asynchat. I have read that twisted makes this all simple, but, I wanted to get my hands dirty here for educational purposes. I've managed to build a small echo server with asyncore and asynchat that can handle any number of...
5
5944
by: David M. Wilson | last post by:
Hi peeps, I finally got around recently to doing something serious using Python for serving network clients asynchronously, deciding on asyncore as my starting point. After 2 days or so of fiddling about, I have decided, as many before me have, that the current asyncore module is the most inflexible, brain-dead, and useless module to be found on the face of the earth!
3
5269
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not have a programmable exit condition. It keeps looping till the channels in its socket map (a dictionary) are closed and don't have any pending reads/writes. If you are using Python threads in your application, by using either the threading or...
1
3026
by: export | last post by:
Is there any tutorial and docs with samples how to use asyncore module? Thanks Lad
0
1766
by: Tony Meyer | last post by:
Changes in asyncore from 2.3 to 2.4 mean that asyncore.poll() now passes all the sockets in the map to select.select() to be checked for errors, which is probably a good thing. If an error occurs, then handle_expt() is called, which by default logs the error. asyncore.dispatcher creates nonblocking sockets. When connect_ex() is called on a nonblocking socket, it will probably return EWOULDBLOCK (connecting takes time), which may mean...
5
7116
by: JamesHoward | last post by:
I have a problem with python's asyncore module throwing a bad file descriptor error. The code might be difficult to copy here, but the problem is essentially: The server wants to sever the connection of an open Asyncore socket. Calling the socket.close() nor the socket.shutdown(2) calls seem to work. The only way I can close the connection without creating the error below is to have the client close the connection. I have the...
2
2079
by: Indy | last post by:
Greetings. I am writing an asynchronous server, and I use the standard library's module asyncore. I subclass asyncore.dispatcher. handle_accept works just right, that is, when a client socket makes a request to connect to my server socket, things that I set in handle_accept definition, happen. So, it is OK. But, the problem is that handle_read does not work as expected. Things I set in handle_read definition, do not happen when a client...
7
2753
by: billie | last post by:
Hi all. I've just terminated a server application using asyncore / asynchat frameworks. I wrote a test script that performs a lot of connections to the server app and I discovered that asyncore (or better, select()) can manage only a limited number of file descriptors (aka simultaneous connections). When this number is reached select() raises an error but asyncore doesn't handle this exception (a crash occurs). If you want to try this I...
4
4463
by: Giampaolo Rodola' | last post by:
Hi there. We're talking about an asyncore-based server. Just for the heck of it I'd like to set a timeout which will disconnects the clients if they're inactive (i.e., no command or data transfer in progress) for a long period of time. I was thinking about putting the timeout value into an attribute: def settimeout(self, secs): self.timeout = time.time() + secs
0
1119
by: Giampaolo Rodola' | last post by:
Hi, I post this message here in the hope someone using asyncore could review this. Since the thing I miss mostly in asyncore is a system for calling a function after a certain amount of time, I spent the last 3 days trying to implement this with the hopes that this could be included in asyncore in the the future.
0
9837
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11250
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10941
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7185
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4293
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3300
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.