Esempio n. 1
0
 def run(self):
   while not instance.has_exited:
     data = self.cs.recv(1024) #blocking
     if not data:  
       break
     #print '[recv]', data
     strs = data.split(':')
     
     instance.gmutex.acquire()
     if strs[instance.MODULE] == 'master':
       master.handle_message(data, self.cs)
     else:
       messages.handle_message(data)
     instance.gmutex.release()
   self.cs.close()
Esempio n. 2
0
def join_meeting():
  try:
    url = "http://ec2-50-112-192-196.us-west-2.compute.amazonaws.com:1337/lookup?id=" + str(instance.meeting_id)
    data = urllib2.urlopen(url).read()  #blocking (with only 1 thread)
    strs = data.split(':')
    print "Contacting master (" + strs[0] + ")..."
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((strs[1], int(strs[2])))  #blocking (with only 1 thread)
    connection_list[strs[0]] = sock
    send(strs[0], "master:join:" + "password" + ":" + instance.local_ip + ":" + str(instance.listen_port))
    data = sock.recv(4096)
    messages.handle_message(data)
  except:
    print "Error! Cannot connect to meeting!"
    sys.exit(1)
Esempio n. 3
0
File: quiz.py Progetto: wd5/quizGame
def rooms_ws():
    if 'wsgi.websocket' in request.environ:
        ws = request.environ['wsgi.websocket']
        g.rooms = rooms
        room_number = None
        player_name = None

        while True:
            message = ws.receive()

            if message is None:
                messages.handle_disconnect(room_number, player_name)
                break
            else:
                message = simplejson.loads(message)
                room_number = int(message['room'])
                player_name = message['user']
                messages.handle_message(message, room_number, player_name, ws)

    return