I'm running into a problem where it won't send data while pyglet.app is running, even when added as a schedule_interval. After I close the window it seems to read that data was sent. Here is my code:
Sever.py #!usr/bin/python import socket, thread, time, json currentUsers = {} collidables = json.loads(json.dumps("")) map_size = 100 maxPlayers = 50 current_IP = socket.gethostbyname(socket.gethostname()) def Timer(): global waiting while True: waiting = False time.sleep(0.05) print "-" waiting = True time.sleep(0.1) def Admin(): print "Creating Admin port %s" % str(4999) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create new socket s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1) # set to reusable s.bind(('',4999)) # bind said socket s.listen(1) client, address = s.accept() # wait for new connection while True: data = client.recv(size) if data == "/UserList": client.sendall(str(currentUsers)) print currentUsers def Thread(port): global host, size, nextPort, waiting, maxPlayers print "\r \rCreating User ports %d/%d" % (port-5000, maxPlayers), while True: try: # Create socket and wait for connection s = socket.socket(socket.AF_INET, socket.SOCK_STREAM ) # create new socket s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # set to reusable s.bind(('',port)) # bind said socket s.listen(1) client, address = s.accept() # wait for new connection username = client.recv(100) print "Port %s connected to \"%s\" %s" % (str(port), username, str(address)) currentUsers[str(port)] = str(address) + " | " + username client.sendall(str(map_size)) # Main loop, adds point to hashmap while True: data = client.recv(size) print data+"+" while waiting: pass if data: # print "Recieved from port %s (%s)" % (port, str(address[1])) data_json = json.loads(json.dumps( data)) collidables.append(data_json) client.sendall(str(collidables)) print collidables+"." while not(waiting): pass client.close() s.close() break except socket.error: # Add something to check for timeouts \ Quitters print "\"%s\" in port %s left %s" % (username,str( port),str(address)) client.close() s.close() except: print "\nFailed to Create port %s" % str(port) client.close() s.close() time.sleep(1) nextPort-=1 NeedNewThread = True break host = 'localhost' nextPort = 5000 size = 1000000 hashMap = {} waiting = True print current_IP thread.start_new_thread(Admin,()) thread.start_new_thread(Timer,()) time.sleep(0.5) while nextPort < 5000+maxPlayers+1: thread.start_new_thread(Thread,(nextPort,)) time.sleep(0.1) nextPort+=1 print "" while True: pass Client.py from pyglet.window import Window,key from pyglet import app from pyglet.text import Label from pyglet.clock import schedule_interval import random, socket Keys = [False,False,False,False,False] # [W,A,S,D,FIRE] last = Keys bullets = [] bullet_speed = 3 bullet_life = 5 point = {'x':0,'y':0} size = 100 # query server for size map_size=10 username = "Lemonilla" # Game Setup print "Enter IP of the server you with to connect to." server_IP = raw_input(">") port = None while port == None: for x in xrange(0,50): try: print "\r \r Attempting socket %d" % (5000+x), server = socket.socket(socket.AF_INET, socket. SOCK_STREAM) server.connect((server_IP,5000+x)) port = 5000+x break except: pass server.sendall(username) print "\n Waiting for server to respond. . ." size = server.recv(10) print " Launching Game. . ." win = Window() ScreenMap = Label("") def move(): global Keys,point,last if Keys[0] == True: # W point['y']+=1 if Keys[1] == True: # A point['x']-=1 if Keys[2] == True: # S point['y']-=1 if Keys[3] == True: # D point['x']+=1 if Keys[4] == True: # SPACE Fire() last = Keys def Fire(): global last # bullet = [x, y, distance to travel, direction] # (W, A, S, D, FIRE) bullets.append((point['x'], point['y'], bullet_life, list(last))) def decay(): global bullets index=0 for b in bullets: bullet_x=b[0] bullet_y=b[1] if b[3][0] == True: bullet_y=b[1]+bullet_speed if b[3][2] == True: bullet_y=b[1]-bullet_speed if b[3][1] == True: bullet_x=b[0]-bullet_speed if b[3][3] == True: bullet_x=b[0]+bullet_speed if b[2]-1 > 0: bullets[index] = (bullet_x, bullet_y, b[2]-1, b[3]) else: bullets[index] = None index+=1 while bullets.count(None) > 0: bullets.remove(None) def check_crash(): return send = "{\'"+str(username)+"\':"+str(bullets)+"}" server.sendall(send) print send # Query Server for Colidables list collidables = server.recv(1000000) print collidables def buildScreen(): global ScreenMap, win, point, map_size screen = "" for y in xrange(point['y']+map_size+1,point['y']-map_size,-1): for x in xrange(point['x']-map_size-1,point['x']+map_size): if not(x == point['x'] and y == point['y']): printed = False for b in bullets: if x == b[0] and y == b[1]: if not(printed): screen+=" +" printed = True if not(printed): screen+=" . " else: screen+=" @" screen+="\n" ScreenMap = Label(str(screen), x=0, y=win.height, width=win.width, multiline=True) @win.event def on_key_press(symbol, modifiers): global Keys,ScreenMap if symbol == key.A: Keys[1] = True if symbol == key.S: Keys[2] = True if symbol == key.W: Keys[0] = True if symbol == key.D: Keys[3] = True if symbol == key.SPACE: Keys[4] = True win.clear() ScreenMap.draw() @win.event def on_key_release(symbol, modifiers): global Keys,ScreenMap if symbol == key.A: Keys[1] = False if symbol == key.S: Keys[2] = False if symbol == key.W: Keys[0] = False if symbol == key.D: Keys[3] = False if symbol == key.SPACE: Keys[4] = False win.clear() ScreenMap.draw() def update(dt): global Keys,ScreenMap,point buildScreen() move() decay() check_crash() win.clear() ScreenMap.draw() point_label = Label("%d,%d" % (point['x'],point['y'])) point_label.draw() schedule_interval(update, 0.1) app.run() -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users+unsubscr...@googlegroups.com. To post to this group, send email to pyglet-users@googlegroups.com. Visit this group at http://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/d/optout.