January 28th, 2003, 06:49 PM
Network sockets problem
I'm writing a network game, and I've hit a little snag that is caused more by my lack of clarity about the use of sockets in Python than any syntax error. Basically, the game's logic works from within the function main(), which looks something like this:
Usually, without the server bits, it all works fine. Now it seems to start up the game code, and get into the loop. It recognises when the client connects, and prints to the shell any data the client sends, but it won't respond to any keyboard events.
set-up game stuff
sockobj = socket(AF_INET, SOCK_STREAM)
connection, address = sockobj.accept()
more set-up stuff
for event in pygame.event.get():
monitor for keyboard events
data = connection.recv(1024)
if not data: break
The sockets code seems to be "hogging" the input. Is this what is happening? Can somebody give me a hint here as to how I should go about this?
January 29th, 2003, 12:16 AM
January 29th, 2003, 05:34 AM
Aha, this looks promising:
It stops the recv() function from waiting for some data before returning, so it should just allow the loop to procede, and only act on data if it gets it. I'll wander back to my room and give it a go; thanks!