
January 28th, 2003, 06:49 PM
|
 |
Wacky hack
|
|
Join Date: Apr 2001
Location: London, England
Posts: 513
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
|
|
|
Network sockets problem
Hullo,
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:
Code:
def main():
set-up game stuff
if server:
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((hostname,port))
sockobj.listen(1)
connection, address = sockobj.accept()
more set-up stuff
while 1:
for event in pygame.event.get():
monitor for keyboard events
if server:
if connection.recv(1024):
data = connection.recv(1024)
if not data: break
print data
update screen
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.
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?
|