Exemplo n.º 1
0
 def start_server(self):
     while True:
         msg, addr = self.sock.recvfrom(1024)
         m = msg.split(":")
         if msg.startswith("ack"):
             print m
             self.base = int(m[1]) + 1
             if self.base != self.nextseqnum:
                 thread.start_new_thread(self.start_timer, (self.base))
         elif msg.startswith("msg_from"):
             if m[1] not in self.receivers:
                 self.receivers[m[1]] = receiver()
             if int(m[2]) == self.receivers[m[1]].expectedseqnum:
                 print msg
                 self.receivers[m[1]].expectedseqnum += 1
                 ack_sock = common.create_sock()
Exemplo n.º 2
0
 def start(self):
     while True:
         msg, addr = self.sock.recvfrom(1024)
         info = msg.split(":")
         if msg.startswith("new"):
             self.clients[info[1]] = client(info[2:])
         elif msg.startswith("msg"):
             receiver = info[3]
             c = self.clients[receiver]
             if (int(info[1])) == c.expectedseqnum:
                 sender = info[2]
                 receiver_sock = (c.ip, c.port)
                 send_sock = common.create_sock()
                 send_sock.sendto(
                     "msg_from:" + sender + ":" + info[1] + ":" + info[4],
                     receiver_sock)
                 c.expectedseqnum += 1
     self.sock.close()
Exemplo n.º 3
0
 def setup(self):
     self.sock = common.create_sock()
     self.sock.bind(common.SERVER)
     print "server listening", common.SERVER
Exemplo n.º 4
0
 def udt_send(msg):
     send_sock = common.create_sock()
     send_sock.sendto(msg, common.SERVER)
     send_sock.close()
Exemplo n.º 5
0
 def send_details(self):
     send_sock = common.create_sock()
     send_sock.sendto(
         "new:" + self.username + ":" + self.ip + ":" + str(self.port),
         common.SERVER)
     send_sock.close()