Пример #1
0
def start(ip=None, port=None):
    global _socket
    try:
        print "IP: ", ip
        print "port", port
        connect_socket(ip, port)
        register()
        while 1:
            data = _receive()
            if data['msg_name'] == "round":
                # print "I'm in round"
                startTime = time.time()
                message = service.round(data)
                send_dict(message)
                endTime = time.time()
                print 'Time consuming: ', (endTime - startTime) * 1000, 'ms'
            elif data['msg_name'] == "leg_start":
                print "I'm in leg_start"
                service.leg_start(data)
            elif data['msg_name'] == "leg_end":
                service.leg_end(data)
            elif data['msg_name'] == "game_over":
                service.game_over(data)
                return
            else:
                print "invalid msg_name."
    except socket.error:
        print "can not connect with server. %s,%s" % (ip, port)
    except Exception as e:
        traceback.print_exc()
        print "some error happend. the receive data:"
        print data
    finally:
        if _socket:
            _socket.close()
Пример #2
0
def start(ip=None, port=None):
    global _socket
    try:
        connect_socket(ip, port)
        register()
        while 1:
            data = _receive()
            if data['msg_name'] == "round":
                message = service.round(data)
                send_dict(message)
            elif data['msg_name'] == "leg_start":
                service.leg_start(data)
            elif data['msg_name'] == "leg_end":
                service.leg_end(data)
            elif data['msg_name'] == "game_over":
                service.game_over(data)
                return
            else:
                print("invalid msg_name.")
    except socket.error:
        print("can not connect with server. %s,%s" % (ip, port))
    except Exception as e:
        print("some error happend. the receive data:", data, type(data))
    finally:
        if _socket:
            _socket.close()
Пример #3
0
def start(ip=None, port=None):
    global _socket
    _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    data = None
    try:
        connect_socket(ip,port)

        logger.debug("Tri to register.")
        register()
        while 1:
            data = _receive()
            if data is None:
                break
            # logger.debug(data)

            if data['msg_name'] == "round":
                message = service.round(data)
                send_dict(message)
            elif data['msg_name'] == "leg_start":
                service.leg_start(data)
            elif data['msg_name'] == "leg_end":
                service.leg_end(data)
            elif data['msg_name'] == "game_over":
                service.game_over(data)
                logger.info("Server Exit")
                return
            else:
                print("invalid msg_name.")
    except socket.error:
        print("can not connect with server. %s,%s" % (ip, port))
        exit()
    except Exception as e:
        print("[start] some error happend: %s. the receive data: %s" % (e, data) )
        traceback.print_exc()
    finally:
        if _socket:
            _socket.close()
        logger.info("Client Closed")