Exemple #1
0
def timeout2():
    global experimentDone, timer, retransmit, base, timeoutInterval, isR1connected, isR2connected
    retransmit = True
    if not experimentDone:
        with buffLock:
            with timerLock:
                timer.cancel()
                timer = threading.Timer(timeoutInterval, timeout2)
                timer.start()
        with baseLock:
            print "Retransmitting from", base, " to", seqnum
            for i in range(base, seqnum):
                if not (isR1connected):
                    data = packet.pack(i, buff[i])
                    gen.talkSockets["r2"].send(data)
                    print "\t packet ", i, " sent to r2"
                elif not (isR2connected):
                    data = packet.pack(i, buff[i])
                    gen.talkSockets["r1"].send(data)
                    print "\t packet ", i, " sent to r1"
                elif i % 2 == 0:
                    data = packet.pack(i, buff[i])
                    gen.talkSockets["r1"].send(data)
                    print "\t packet ", i, " sent to r1"
                elif i % 2 == 1:
                    data = packet.pack(i, buff[i])
                    gen.talkSockets["r2"].send(data)
                    print "\t packet ", i, " sent to r2"
            retransmit = False
Exemple #2
0
def sendPacket2():
    global buff, experimentDone, base, timer, seqnum, isR1connected, isR2connected
    while not experimentDone:
        if not retransmit:
            with baseLock:
                tempBase = base
            if seqnum <= packet.size:
                if seqnum < tempBase + windowSize:
                    if not isR1connected:
                        data = packet.pack(seqnum, buff[seqnum])
                        gen.talkSockets["r2"].send(data)
                        print "packet ", seqnum, " sent to r2"
                    elif not isR2connected:
                        data = packet.pack(seqnum, buff[seqnum])
                        gen.talkSockets["r1"].send(data)
                        print "packet ", seqnum, " sent to r1"
                    elif seqnum % 2 == 0:
                        data = packet.pack(seqnum, buff[seqnum])
                        gen.talkSockets["r1"].send(data)
                        print "packet ", seqnum, " sent to r1"
                    elif seqnum % 2 == 1:
                        data = packet.pack(seqnum, buff[seqnum])
                        gen.talkSockets["r2"].send(data)
                        print "packet ", seqnum, " sent to r2"
                    if tempBase == seqnum:
                        with timerLock:
                            timer.cancel()
                            timer = threading.Timer(timeoutInterval, timeout2)
                            timer.start()
                    seqnum += 1
                else:
                    with baseCond:
                        baseCond.wait()
                time.sleep(0.02)
def main():
    s = socket()
    s.bind(("localhost", 3030))
    s.listen(1)

    conn, addr = s.accept()

    while True:
        #mensaje recivido
        incoming_data = conn.recv(1024)
        print("mensaje recivido en incomingdata del lado servidor" +
              incoming_data)
        if incoming_data:
            packet_id, message = packet.unpack(incoming_data)

            if packet_id == packet.MESSAGE:
                packet.send(
                    conn,
                    packet.pack(
                        packet.MESSAGE,
                        'servicio')  #incoming_data debe recivir servicio
                )
                print("incomingdata del lado ddel server" + incoming_data)
            elif packet_id == packet.PING:
                packet.send(conn, packet.pack(packet.PING, ""))

    s.close()
Exemple #4
0
 def login(self, username, password):
     self.username = username
     #self.session.send(username + ':' + password)
     req = user_pb2.LoginReq()
     req.username = username
     req.password = password
     md5 = hashlib.md5()
     md5.update(req.password)
     req.password = md5.hexdigest()
     self.session.send(packet.pack(opcode_pb2.LOGIN_REQ, req))
def main():
    s = socket()
    s.connect(("localhost", 3030))
    while True:
        message = raw_input("Manda algo al servidor> ")
        print("Justo despues de mter en el input " + message)

        if message.lower() == "ping":
            output_data = packet.pack(packet.PING, "")
            ticks = time()
        else:
            output_data = packet.pack(packet.MESSAGE, message[1:])
            print("Mensaje del message[1:] en cliente" + output_data)
        #elif message.lower() == 'servicio':
        #output_data = packet.pack(packet.MESSAGE, message[1:])

        packet.send(s, output_data)
        print("impresion del cliente del outData" + output_data)
        incoming_data = s.recv(1024)
        print("impresion del cliente del incoData" + incoming_data)

        if incoming_data:
            packet_id, message = packet.unpack(incoming_data)
            if packet_id == packet.MESSAGE:
                if isinstance(message, bytes):
                    print("asasas" + message)
                    message = message.decode("utf-8")
                    print("Mensaje con decode" + message)
                #print("El servidor ha respondido: %s." % message)
                if message == 'servicio':
                    import ConOpenCv
                    pass
                print("Este mensaje es " + message)
            elif packet_id == packet.PING:
                ticks = (time() - ticks) / 2
                print("Ping: %.2f ms." % ticks)

    s.close()
Exemple #6
0
def timeout1():
    global experimentDone, timer, retransmit, base, timeoutInterval
    retransmit = True
    if not experimentDone:
        with buffLock:
            with timerLock:
                timer.cancel()
                timer = threading.Timer(timeoutInterval, timeout1)
                timer.start()
        with baseLock:
            print "Retransmitting from", base, " to", seqnum
            for i in range(base, seqnum):
                data = packet.pack(i, buff[i])
                gen.talkSockets["r3"].send(data)
                print "\t packet ", i, " sent to r3"
            retransmit = False
    def send_data(self, data):
        '''
        Sends a data packet over the connection. This is allowed to be any
        Python object that supports pickling.
        '''
        header_data = {
            's_uniqid': int(self.node, 16),
            'msg_mj_type': ord('s'),
            'msg_mi_type': ord('d'),
        }

        message_data = zlib.compress(pickle.dumps(data))

        for data in pack(header_data, message_data):
            self.channel.basic_publish(exchange='waggle_in',
                                       routing_key='in',
                                       body=data)
    def send_data(self, data):
        '''
        Sends a data packet over the connection. This is allowed to be any
        Python object that supports pickling.
        '''
        header_data = {
            's_uniqid': int(self.node, 16),
            'msg_mj_type': ord('s'),
            'msg_mi_type': ord('d'),
        }

        message_data = zlib.compress(pickle.dumps(data))

        for data in pack(header_data, message_data):
            self.channel.basic_publish(exchange='waggle_in',
                                       routing_key='in',
                                       body=data)
Exemple #9
0
def sendPacket1():
    global buff, experimentDone, base, timer, seqnum, retransmit
    while not experimentDone:
        if not retransmit:
            with baseLock:
                tempBase = base
            if seqnum <= packet.size:
                if seqnum < tempBase + windowSize:
                    data = packet.pack(seqnum, buff[seqnum])
                    gen.talkSockets["r3"].send(data)
                    print "packet ", seqnum, " sent to r3"
                    if tempBase == seqnum:
                        with timerLock:
                            timer.cancel()
                            timer = threading.Timer(timeoutInterval, timeout1)
                            timer.start()
                    seqnum += 1
                else:
                    with baseCond:
                        baseCond.wait()
                time.sleep(0.02)
Exemple #10
0
import time
import packet
import socket
from proto import game_pb2


def hex_str(s):
    return ":".join("{0:x}".format(ord(c)) for c in s)

if __name__ == '__main__':
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("127.0.0.1", 8888))

    login_packet = game_pb2.Login()
    login_packet.name = 'tang'
    login_packet.password = '******'

    buf = packet.pack(101, login_packet)
    print  hex_str(buf)
    sock.send(buf)

    time.sleep(10)
Exemple #11
0
 def exec_cmd(self, userId, cmd):
     req = user_pb2.ExecCmdReq()
     req.cmd = cmd
     req.target_uid = userId
     self.session.send(packet.pack(opcode_pb2.EXEC_CMD_REQ, req))
Exemple #12
0
 def onlines(self):
     req = common_pb2.NullMessage()
     self.session.send(packet.pack(opcode_pb2.ONLINE_USERS_REQ, req))