예제 #1
0
 def __init__(self, host='localhost', port=65000, robot='mana'):
     """ Create the socket that will be used to commmunicate to the server. """
     self.robot = robot
     self.node_stream = None
     logger.debug("Connecting to %s:%d" % (host, port))
     try:
         self.node_stream = StreamJSON(host, port)
         self.poll_thread = PollThread()
         self.poll_thread.start()
         if self.node_stream.connected:
             logger.info("Connected to %s:%s" % (host, port))
     except Exception as e:
         logger.info("Multi-node simulation not available!")
         logger.warning("Unable to connect to %s:%s" % (host, port))
         logger.info(str(e))
예제 #2
0
def publish_stream(socketio, frequency=1):
    node_stream = StreamJSON("localhost", 65000)
    poll_thread = PollThread()

    poll_thread.start()

    while node_stream.is_up():
        node_stream.publish(["morseweb", {}])

        try:
            data = node_stream.get(timeout=1e-3) or node_stream.last()
        except JSONDecodeError:
            pass
        else:
            socketio.emit("simulator.update", data)

        time.sleep(frequency)
예제 #3
0
파일: socket.py 프로젝트: mitya57/morse
 def initialize(self):
     """
     Create the socket that will be used to commmunicate to the server.
     """
     self.node_stream = None
     self.poll_thread = None
     logger.debug("Connecting to %s:%d" % (self.host, self.port) )
     try:
         self.node_stream = StreamJSON(self.host, self.port)
         self.poll_thread = PollThread()
         self.poll_thread.start()
         if self.node_stream.connected:
             logger.info("Connected to %s:%s" % (self.host, self.port) )
     except Exception as err:
         logger.info("Multi-node simulation not available!")
         logger.warning("Unable to connect to %s:%s"%(self.host, self.port) )
         logger.warning(str(err))