Пример #1
0
 def handle_stream(self, stream, address):
     LOGGER.info('torch %s connected', address)
     for _ in range(20):
         msg = random.choice([
             struct.pack('>BB', 18, 0),
             struct.pack('>BB', 19, 0),
             struct.pack('>BBBBB', 32, 3, random.randint(0, 250), random.randint(0, 250), random.randint(0, 250))
         ])
         try:
             stream.write(msg)
         except iostream.StreamClosedError:
             LOGGER.warning(
                 'connection with %s closed unexpectedly', address)
             return
         time.sleep(.5)
     LOGGER.info('closing connection with %s', address)
Пример #2
0
from tornado import tcpserver

from lamp_ivideon.settings import LOGGER


class TorchTestServer(tcpserver.TCPServer):
    def handle_stream(self, stream, address):
        LOGGER.info('torch %s connected', address)
        for _ in range(20):
            msg = random.choice([
                struct.pack('>BB', 18, 0),
                struct.pack('>BB', 19, 0),
                struct.pack('>BBBBB', 32, 3, random.randint(0, 250), random.randint(0, 250), random.randint(0, 250))
            ])
            try:
                stream.write(msg)
            except iostream.StreamClosedError:
                LOGGER.warning(
                    'connection with %s closed unexpectedly', address)
                return
            time.sleep(.5)
        LOGGER.info('closing connection with %s', address)


if __name__ == '__main__':
    server = TorchTestServer()
    server.listen(9999)
    LOGGER.info('starting torch test server on 127.0.0.1:9999')
    instance = ioloop.IOLoop.instance()
    instance.start()