Ejemplo n.º 1
0
 def handle_placement(self, msg):
     if self.strategy is None:
         emsg = 'no dll loaded'
         logging.error(emsg)
         self.send_error(0, emsg)
     else:
         logging.info("executing func `Placement`")
         self.strategy.dll_placement(msg.env)
         finfo = PlacementInfo(env=msg.env)
         respmsg = message.make_msg(message.MSG_placementinfo,
                                    None,
                                    placementinfo=finfo)
         self.conn.send_msg(respmsg)
Ejemplo n.º 2
0
 def handle_strategy(self, msg):
     if self.strategy is None:
         emsg = 'no dll loaded'
         logging.error(emsg)
         self.send_error(0, "no dll loaded")
     else:
         logging.info("executing func `Strategy`")
         self.strategy.dll_strategy(msg.env)
         wheelinfo = WheelInfo(robot_list=msg.env.home)
         respmsg = message.make_msg(message.MSG_wheelinfo,
                                    None,
                                    wheelinfo=wheelinfo)
         self.conn.send_msg(respmsg)
Ejemplo n.º 3
0
    print("ex: python3 client.py 127.0.0.1 8080\n")
    exit()

IP_address = str(sys.argv[1])
port = int(sys.argv[2])
UDP_port = 8081  # UDP port fixed
client_id = random.randrange(1000, 4001)
#wait for the client to type "Log on" to be connected
while (sys.stdin.readline() != "Log on\n"):
    {}

# create a UDP connection for the intial handshake with server
handshake = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP connection

# send HELLO(clientID_A) message to server using UDP to begin connection
msg = message.make_msg("HELLO", *[str(client_id)])
handshake.sendto(msg.encode(), (IP_address, UDP_port))

handshake.close()

# creates TCP connection with chat server after handshake is complete
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.connect((IP_address, port))

while True:
    # select() does not work on stdin on windows
    sockets_list = [sys.stdin, server]
    read_sockets, write_socket, error_socket = select.select(
        sockets_list, [], [])
    # receive and display messages, if any. Otherwise, read from stdin
    for socks in read_sockets:
Ejemplo n.º 4
0
 def handle_ping(self, msg):
     logging.info('get ping, replying pong')
     self.conn.send_msg(message.make_msg(message.MSG_pong, None))
Ejemplo n.º 5
0
 def send_error(self, errcode, errdesc):
     msg = message.make_msg(message.MSG_error,
                            None,
                            errcode=errcode,
                            errdesc=errdesc)
     self.conn.send_msg(msg)
Ejemplo n.º 6
0
 def send_fin(self):
     self.conn.send_msg(message.make_msg(message.MSG_fin, None))