By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,913 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,913 IT Pros & Developers. It's quick & easy.

Using Asyncore/chat for game server question.

P: n/a
Hello all.

I have a working server, using the asyncore/chat module, which enables
logging in, rooms and private messaging.

I've used this framework to make some simple games that only required
message broadcasting via the server.

I'd now like to move the game logic into the server.

My recent reading includes the article "Multithreaded Game Scripting
with Stackless Python"

I'm not so interested in moving to Stackless, although i've also been
looking at Nanothreads offered in the "Lightweight Game Toolkit" as a
way to implement the above ideas in plain python.

However, that's a bit off from my Question. So here is is:

How do i enable the/a game object, running on the server, to send
messages "on its own". I understand that the asyncore module is based
on the "Reactor" design, which is, duh, reactive rather then active...
So how do i make my server "active" ;).

A simple example would be a server based on asyncore, with multiple
connections, which broadcasts a "pulse" to the connected clients every

Thanks for any help, pointers, words of advice, etc etc!


Sep 29 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Thanks to Matt Hammond and Jonathan LaCour for getting back to me!

Jonathan sent me some code which took me several days to figure out,
but does _exactly_ what i wanted.

You can find the code he sent (dug out of the medusa distro) here:

And how i warped it to my needs here:
(please don't laugh at the rough code! :)

Jonathan's original reply, via email, is quoted here with his


I saw your post to comp.lang.python about asyncore and making a bit
more of an "active" process. The problem with asyncore, as you stated,
is that it "reacts" to events on file descriptors (through
select/poll). If you have something that occurs in a second thread
that could cause data to be available (ie, sending a "pulse" every
second), you can use some old code from the medusa web server to do
this, which I will attached to this email.

You will need to do something like this (I haven't tested this code):

from select_trigger import trigger
from threading import Thread
import time

class pulse_thread(Thread):
def __init__(self, interval, thunk):
self.trigger = trigger()
self.thunk = thunk
self.interval = interval

def run(self):
while True:

The pulse thread will pull the trigger how ever often you like, thus
waking up the asyncore loop for events being fired. I hope this helps.

-- Jonathan

Oct 6 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.