示例#1
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()
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()
示例#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")
示例#4
0
                'y': 19
            }]
        },
        'teams': [{
            'force': 'beat',
            'id': 1111,
            'players': [0, 1, 2, 3]
        }, {
            'force': 'think',
            'id': 1112,
            'players': [4, 5, 6, 7]
        }]
    },
    'msg_name': 'leg_start'
}
ser.leg_start(msg)

start = time.perf_counter()

msg = {
    'msg_data': {
        'mode':
        'beat',
        'players': [{
            'id': 0,
            'score': 42,
            'sleep': 0,
            'team': 1111,
            'x': 1,
            'y': 8
        }, {
示例#5
0
from ballclient.service import service
msg = {'msg_data': {'map': {'height': 20, 'meteor': [{'x': 18, 'y': 1}, {'x': 19, 'y': 1}, {'x': 7, 'y': 4}, {'x': 8, 'y': 4}, {'x': 11, 'y': 4}, {'x': 12, 'y': 4}, {'x': 4, 'y': 7}, {'x': 15, 'y': 7}, {'x': 4, 'y': 8}, {'x': 15, 'y': 8}, {'x': 4, 'y': 11}, {'x': 15, 'y': 11}, {'x': 4, 'y': 12}, {'x': 15, 'y': 12}, {'x': 7, 'y': 15}, {'x': 8, 'y': 15}, {'x': 11, 'y': 15}, {'x': 12, 'y': 15}, {'x': 0, 'y': 18}, {'x': 1, 'y': 18}], 'tunnel': [{'direction': 'up', 'x': 5, 'y': 5}, {'direction': 'right', 'x': 6, 'y': 5}, {'direction': 'right', 'x': 7, 'y': 5}, {'direction': 'right', 'x': 8, 'y': 5}, {'direction': 'right', 'x': 9, 'y': 5}, {'direction': 'right', 'x': 10, 'y': 5}, {'direction': 'right', 'x': 11, 'y': 5}, {'direction': 'right', 'x': 12, 'y': 5}, {'direction': 'right', 'x': 13, 'y': 5}, {'direction': 'right', 'x': 14, 'y': 5}, {'direction': 'up', 'x': 5, 'y': 6}, {'direction': 'down', 'x': 14, 'y': 6}, {'direction': 'up', 'x': 5, 'y': 7}, {'direction': 'down', 'x': 14, 'y': 7}, {'direction': 'up', 'x': 5, 'y': 8}, {'direction': 'down', 'x': 14, 'y': 8}, {'direction': 'up', 'x': 5, 'y': 9}, {'direction': 'down', 'x': 14, 'y': 9}, {'direction': 'up', 'x': 5, 'y': 10}, {'direction': 'down', 'x': 14, 'y': 10}, {'direction': 'up', 'x': 5, 'y': 11}, {'direction': 'down', 'x': 14, 'y': 11}, {'direction': 'up', 'x': 5, 'y': 12}, {'direction': 'down', 'x': 14, 'y': 12}, {'direction': 'up', 'x': 5, 'y': 13}, {'direction': 'down', 'x': 14, 'y': 13}, {'direction': 'left', 'x': 5, 'y': 14}, {'direction': 'left', 'x': 6, 'y': 14}, {'direction': 'left', 'x': 7, 'y': 14}, {'direction': 'left', 'x': 8, 'y': 14}, {'direction': 'left', 'x': 9, 'y': 14}, {'direction': 'left', 'x': 10, 'y': 14}, {'direction': 'left', 'x': 11, 'y': 14}, {'direction': 'left', 'x': 12, 'y': 14}, {'direction': 'left', 'x': 13, 'y': 14}, {'direction': 'down', 'x': 14, 'y': 14}], 'vision': 3, 'width': 20, 'wormhole': [{'name': 'A', 'x': 19, 'y': 0}, {'name': 'b', 'x': 13, 'y': 6}, {'name': 'a', 'x': 6, 'y': 13}, {'name': 'B', 'x': 0, 'y': 19}]}, 'teams': [{'force': 'beat', 'id': 1111, 'players': [0, 1, 2, 3]}, {'force': 'think', 'id': 1112, 'players': [4, 5, 6, 7]}]}, 'msg_name': 'leg_start'}
service.leg_start(msg)
msg = {'msg_data': {'mode': 'beat', 'players': [{'id': 4, 'score': 0, 'sleep': 0, 'team': 1112, 'x': 1, 'y': 0}, {'id': 5, 'score': 0, 'sleep': 0, 'team': 1112, 'x': 10, 'y': 0}, {'id': 6, 'score': 0, 'sleep': 0, 'team': 1112, 'x': 9, 'y': 19}, {'id': 7, 'score': 0, 'sleep': 0, 'team': 1112, 'x': 18, 'y': 19}], 'power': [{'point': 1, 'x': 3, 'y': 2}, {'point': 1, 'x': 7, 'y': 2}, {'point': 1, 'x': 12, 'y': 2}, {'point': 1, 'x': 2, 'y': 3}, {'point': 1, 'x': 17, 'y': 16}, {'point': 1, 'x': 7, 'y': 17}, {'point': 1, 'x': 12, 'y': 17}, {'point': 1, 'x': 16, 'y': 17}], 'round_id': 0, 'teams': [{'id': 1111, 'point': 0, 'remain_life': 4}, {'id': 1112, 'point': 0, 'remain_life': 4}]}, 'msg_name': 'round'}
service.round(msg)