Using Asyncore/chat for game server question.

2005-09-29 Thread 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/10/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.

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

-- 
http://mail.python.org/mailman/listinfo/python-list


Thread's, async_chat and asyncore

2005-10-03 Thread Jos
Hello.

I'm using the asyncore and _chat modules to create a network server. I
also have, running in a separate thread(s), a "producer" which needs to
"push" data onto the network connection(s). (This is all for a
multi-player game server, so the threads would be individual games,
that need to update the players when new events happen in the game)

I currently have a module level list of async_chat instances, which the
thread then reads and uses the 'push' method of async_chat.

I've done some very quick tests, but wanted to know more formally if
the async_chat.push() method is thread safe?

ie. can i be sure that the data that the thread pushes onto the
connection will always be complete, and never "over-written" by another
thread?

Here is an example, which creates a whack of threads, which push their
message down the first connection made to the server. I just use a
telnet client to test it. I haven't seen any over-writing of values,
but this is a very basic test/example of what i'm doing. I just want to
make sure that this _is_ ok, or if i should be using a Queue...


import asynchat
import asyncore
import socket
from threading import Thread
import time
import random

clients = []

class pulse_thread(Thread):
def __init__(self, string):
Thread.__init__(self)
self.msg = string

def run(self):
while True:
time.sleep(random.random())
if(len(clients)):
clients[0].push(self.msg)

class Chat(asynchat.async_chat):

def __init__(self, sock, addr, terminator="\r\n", name="me"):

asynchat.async_chat.__init__(self, conn=sock)

self.rmq = []
self.terminator = terminator
self.set_terminator(self.terminator)
# push self onto module client list, so threads can access me
clients.append(self)

def collect_incoming_data(self, data):
"""Buffer the data"""
self.rmq.append(data)

def found_terminator(self):
print "".join(self.rmq)
self.rmq = []

class cServer(asyncore.dispatcher):

# constructor method
def __init__(self, addr, terminator="\r\n"):

# initalize asyncore
asyncore.dispatcher.__init__(self)

self.terminator = terminator

# create a socket to listen on
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)

# bind the socket to the ip/port
self.bind(addr)

# listen ??? don't know about the 5 
self.listen(50)

# EVENT handle_accept - fired when server accepts an new connection
def handle_accept (self):
# fire the accept method > returns a connection object
conn, addr = self.accept()

# extend the connection with cSock Class (another asyncore)
#cSock(conn, addr)
Chat(conn,addr,self.terminator)


if __name__ == '__main__':

for i in range(1,99):
x = pulse_thread(":%02d:\n\r" % (i,))
    x.start()

myserver = cServer(('127.0.0.1',7000))

asyncore.loop()


Please let me know if this is totally the _wrong_ way to do it!

Thanks,
Jos

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thread's, async_chat and asyncore

2005-10-03 Thread Jos
Gaaa, i just did a run with 999 threads pushing data, and i'm getting
"IndexError: deque" problems, so i'm guessing its _not_ thread safe...

Bummer.

jos

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Asyncore/chat for game server question.

2005-10-05 Thread 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/pyasynccpl/select_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


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


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thread's, async_chat and asyncore

2005-10-05 Thread Jos
I will take a look at it, thanks!
jos

-- 
http://mail.python.org/mailman/listinfo/python-list


INVITATION FLIB: Fringe/Functional Languages In Barcelona user group.

2009-05-25 Thread jos koot
INVITATION
We, (Jose A. Ortega Ruiz j...@gnu.org, Andy Wingo wi...@pobox.com and
Jos Koot jos.k...@telefonica.net) have scheduled a meeting in
Barcelona (Spain) with the intention to form a user group FLIB: Fringe/
Functional Languages In Barcelona. Everyone who is interested in
shaping this group is invited to share us.

June 10 2009 at 7.30 PM
Calle del Pi 3 Principal Interior (first floor)
Barcelona
Spain

Preliminary program

Welcome.
Short discussion about what FLIB should be and should not be.
Jose: communication about FUEL (Factors Ultimate Emacs Library)
Jos : 5 minute click/lightning talk on his recent experiences with
PLT's redex library.
You: 5 minut click/lightning talk.
Many more of you: 5 minut click/lightning talks.
Informal meeting in the conference room or in a bar or simple
restaurant within walking distance.

The preferred language is English, but click talks can also be in
Castiliano (Spanish) or in Catala.
If you intend to come, let us know by email, please, in order that we
can estimate the number of participants.
If you intend to do a click talk, please let us know too.

Please forward this invitation to relevant mailing lists we may have
missed.
Hope to meet you on June the tenth.

j...@gnu.org
wi...@pobox.com
jos.k...@telefonica.net
-- 
http://mail.python.org/mailman/listinfo/python-list


XML-RPC server via xinetd

2006-04-15 Thread Jos Vos
Hi,

I'm trying to figure out how to implement a XML-RPC server that
is called by xinetd i.s.o. listening on a TCP socket itself.

I already have implemented a stand-alone XML-RPC server using
SimpleXMLRPCServer, but I now want something similar, that is
started via xinetd (i.e. reading/writing via stdin/stdout).

Any hints or code examples?

Thanks,

-- 
--    Jos Vos <[EMAIL PROTECTED]>
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC server via xinetd

2006-04-16 Thread Jos Vos
On Sun, Apr 16, 2006 at 10:13:19PM +0200, Martin P. Hellwig wrote:

> Isn't this just a standard daemon functionality?

What is "a standard daemon"? :-)

> So if you could wrap up your program in a daemon like fashion (e.g. 
> http://homepage.hispeed.ch/py430/python/daemon.py) and then point the 
> xinetd configuration to the right script, it should just work?

In fact, the standard use *is* a daemon (that is, accepting connections
on a certain port) and I want it to be *not* a daemon.  For the daemon
method I use something similar to "daemonize", but now I want it to
*not* do the binds etc. to listen on a port.

The problem is that the server initialization *requires* a server
address (host, port pair), but I don't see how to tell it to use
the stdin socket (and I'm afraid this is not possible, but I'm not
sure).

-- 
--Jos Vos <[EMAIL PROTECTED]>
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC server via xinetd

2006-04-17 Thread Jos Vos
On Mon, Apr 17, 2006 at 02:07:37AM +0200, Martin P. Hellwig wrote:

> If I understood it correctly you want the python server bind be 
> depending on whatever is configured in xinetd.conf and not be defined in 
> the your program itself?
> 
> I tested a bit around with my FreeBSD machine but indeed the OS 
> environment gives me nothing interesting back, leaving that option out 
> but I do can specify command line arguments so you could pick them up 
> with sys.argv.
> 
> I looked up how you can specify arguments in xinetd and according to 
> various resources I filtered out (gotta over these gnu type 
> documentation...) that you can use "server_args" in the per service 
> configuration to specify arguments.
> 
> Although not really elegant it is doable to do an on the fly port binding.
> 
> Now I just hope I understood your problem :-)

No, you didn't :-).  I could add these options or even write an
xinetd-only program, that's all fine with me.

The problem is that I do not see how to let an SimpleXMLRPCServer
instance *not* bind to a port or what other class I can use to just
build a XML-RPC request handler reading/writing from stdin/stdout,
i.s.o.  carrying all the server class stuff with it.

-- 
--Jos Vos <[EMAIL PROTECTED]>
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC server via xinetd

2006-04-17 Thread Jos Vos
On Mon, Apr 17, 2006 at 12:10:15PM +0200, Brian Quinlan wrote:

> If you take a look at CGIXMLRPCRequestHandler 
> (http://docs.python.org/lib/node564.html), you will see an example of 
> how to write an XMLRPCRequestHandler without HTTP.

Thanks, this might work for me, will try it.

-- 
--Jos Vos <[EMAIL PROTECTED]>
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC server via xinetd

2006-04-17 Thread Jos Vos
On Mon, Apr 17, 2006 at 03:30:04AM -0500, Nick Craig-Wood wrote:

> UTSL ;-)
> 
> Look at /usr/lib/python2.4/SimpleXMLRPCServer.py (adjust as per your
> distro) and in particular the definition of the CGIXMLRPCRequestHandler class.

I did this before posting my question, in fact, but I did not look
good enough maybe, as at first sight I thought tghe CGI... class
would be too CGI-specific (it looks for environment variables etc.
given by the HTTP server), but maybe it's good enough.

> That looks as thought it almost, or maybe completely, does what you
> want, ie an XMLRPC subclass which reads from stdin and writes to
> stdout.

Will try...

-- 
--Jos Vos <[EMAIL PROTECTED]>
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC server via xinetd

2006-04-17 Thread Jos Vos
On Mon, Apr 17, 2006 at 12:36:18PM +0200, Brian Quinlan wrote:

> I don't know exactly what your usage pattern is, but you might be able 
> to use SimpleXMLRPCDispatcher directly e.g.
> 
>  >>> s = SimpleXMLRPCDispatcher()
>  >>> s.register_function(pow)
>  >>> s._marshaled_dispatch(' '
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC server via xinetd

2006-04-17 Thread Jos Vos
On Mon, Apr 17, 2006 at 12:42:00PM +0200, Fredrik Lundh wrote:

> except that if the OP's expecting the other end to use an ordinary XML-RPC
> library, he needs to implement some minimal HTTP handling as well.

Which makes me wondering why the classes (this also applies to
BaseHTTPServer / BaseHTTPRequestHandler) ae designed the way they
are.  The underlying stream medium (TCP sockets or plain file
streams like stdin/stdout) should not be integrated with the
protocol (HTTP) handling, IMHO...

-- 
--Jos Vos <[EMAIL PROTECTED]>
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-28 Thread jos...@corporate-world.lisp.de
On 29 Okt., 01:34, Lawrence D'Oliveiro  wrote:
> In message
> , kodifik
> wrote:
>
> > On Oct 28, 1:55 am, Lawrence D'Oliveiro 
> > wrote:
>
> >> Would it be right to say that the only Lisp still in common use is the
> >> Elisp built into Emacs?
>
> > Surely surpassed by autolisp (a xlisp derivative inside the Autocad
> > engineering software).
>
> How many copies of AutoCAD are there? Given its price, probably something in
> the five or six figures at most.

A few million.
-- 
http://mail.python.org/mailman/listinfo/python-list