473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using Asyncore/chat for game server question.

Jos
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"

http://harkal.sylphis3d.com/2005/08/...ckless-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.

http://lgt.berlios.de/#nanothreads

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

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

Jos

Sep 29 '05 #1
1 2644
Jos
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:
http://www.thethirdplace.org/grabbag...ect_trigger.py

And how i warped it to my needs here:
http://www.thethirdplace.org/grabbag/pyasynccpl/test.py
(please don't laugh at the rough code! :)

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

Thanks!
jos

<quote>
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):
Thread.__init__(self)
self.trigger = trigger()
self.thunk = thunk
self.interval = interval

def run(self):
while True:
self.trigger.pull_trigger(self.thunk)
time.sleep(self.interval)

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
</quote>

Oct 6 '05 #2

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

Similar topics

0
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...
1
by: fishboy | last post by:
Howdy, I'm in middle of a personal project. Eventually it will download multipart binary attachments and look for missing parts on other servers. And so far I've got it to walk a newsgroup and...
0
by: fishboy | last post by:
Howdy, Sorry if this is a double post. First try seemed to go into hyperspace. I'm working on a personal project. It's going to be a multipart binary attachment downloader that will search...
2
by: Dustin | last post by:
I've been trying to create a "byte streaming server", it's basically a chat server, but I'd like to use it for transfering large amounts of data between two connected clients. Sounds simple...
1
by: export | last post by:
Is there any tutorial and docs with samples how to use asyncore module? Thanks Lad
4
by: billie | last post by:
Hi all. I'm (re)writing an FTP server application by using asyncore/asynchat modules. FTP tipically got two different channels: command and data. I'm succesfully managing command channel through...
5
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...
2
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...
7
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.