On Thu, Feb 21, 2008 at 9:00 AM, Drew Smathers <[EMAIL PROTECTED]> wrote: > > On Thu, Feb 21, 2008 at 10:50 AM, Nathan <[EMAIL PROTECTED]> wrote: > > > > I'm attempting to write a simple little real-time server-client game > > where the server and client talk to each other over the network. > > > > There is no such thing as a simple real-time server-client game. In > less you mean a not-really-real-time (TM) server-client game.
I'm aware of the realities. I just meant it's not a turn-based game (for example) where 2-second lag would be acceptable. > > My initial implementation uses the built-in socket module, but I can't > > find a way to flush the socket! Any suggestions for a simple way for > > fast communications, or a way to make sockets work fast? (right now, > > the sockets seem to just wait about 2 seconds, and then transmit, > > which is rather funny to watch, but not very playable). > > > > Just use Twisted. Then you might actually come close to the "simple" > objective. Nonetheless, you might want to google TCP_NODELAY for > your particular problem. Twisted and "simple" have nothing to do with each other in my experience. I even bought the Twisted book, but I have a really hard time getting into it (not to mention that the developers seem to live on the opposite side of the world and have odd attitudes when you start asking them questions). I really don't want to deal with a completely separate event loop. I'd also like to avoid external dependencies where possible. (Right now I only depend on python itself and pyglet) I'm researching the TCP_NODELAY option, which looks promising, but there's a curious lack of explanation of those types of flags and how to use the on http://docs.python.org/lib/module-socket.html --- I suppose they assume you'll come with socket knowledge from C. Referencing these sources... http://www.scribd.com/doc/134861/Sockets-Programming-with-python http://mail.python.org/pipermail/python-list/2006-April/378814.html ...I tried doing the following in my code, with no observable effect (still ~1-2 sec lag): (-- server-side snippets --) def player_thread(conn): conn.setsockopt(socket.SOL_SOCKET, socket.TCP_NODELAY, 1) [snip] [snip] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((HOST, PORT)) sock.listen(0) [snip] # Create player_thread's as players connect try: while True: conn, addr = sock.accept() thread_id = thread.start_new_thread(player_thread, (conn,)) except Exception, e: print e finally: sock.close() (-- client-side snippets ---) def server_connection(keystate_queue, updates_queue): # We send keystate to the server # The server sends updates to us conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect((HOST, PORT)) conn.setsockopt(socket.SOL_SOCKET, socket.TCP_NODELAY, 1) [snip] ~ Nathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
