Ejemplo n.º 1
0
            if self.request in ins:
                # Receive client data, decode it, and send it back
                frames, closed = self.recv_frames()
                cqueue.extend(frames)

                if closed:
                    self.send_close()

if __name__ == '__main__':
    parser = optparse.OptionParser(usage="%prog [options] listen_port")
    parser.add_option("--verbose", "-v", action="store_true",
            help="verbose messages and per frame traffic")
    parser.add_option("--cert", default="self.pem",
            help="SSL certificate file")
    parser.add_option("--key", default=None,
            help="SSL key file (if separate from cert)")
    parser.add_option("--ssl-only", action="store_true",
            help="disallow non-encrypted connections")
    (opts, args) = parser.parse_args()

    try:
        if len(args) != 1: raise
        opts.listen_port = int(args[0])
    except:
        parser.error("Invalid arguments")

    opts.web = "."
    server = WebSocketServer(WebSocketEcho, **opts.__dict__)
    server.start_server()

Ejemplo n.º 2
0
        else:
            self._send_error(404, "Invalid URI")

def rest_server():
    server_address = ('', _REST_PORT)
    httpd = HTTPServer(server_address, RESTHandler)
    while True:
        rlist = select.select([httpd.fileno()], [], [], _POLL_TMO)[0]
        if httpd.fileno() in rlist:
            httpd.handle_request()


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    # Check whether zatel daemo is started or not
    try:
        s = ipc_notify_connect()
        s.close()
    except (ConnectionRefusedError, socket.error):
        print("Please start zateld.py first")
        exit(1)

    rest_srv = Thread(target=rest_server)
    rest_srv.daemon = True
    rest_srv.start()

    ws = WebSocketServer(WebSocketDemo, listen_port=_WS_PORT, verbose=True)
    ws.only_upgrade = True
    ws.start_server()
Ejemplo n.º 3
0

if __name__ == '__main__':
    parser = optparse.OptionParser(usage="%prog [options] listen_port")
    parser.add_option("--verbose",
                      "-v",
                      action="store_true",
                      help="verbose messages and per frame traffic")
    parser.add_option("--cert",
                      default="self.pem",
                      help="SSL certificate file")
    parser.add_option("--key",
                      default=None,
                      help="SSL key file (if separate from cert)")
    parser.add_option("--ssl-only",
                      action="store_true",
                      help="disallow non-encrypted connections")
    (opts, args) = parser.parse_args()

    try:
        if len(args) != 1: raise
        opts.listen_port = int(args[0])
    except:
        parser.error("Invalid arguments")

    logging.basicConfig(level=logging.INFO)

    opts.web = "."
    server = WebSocketServer(WebSocketEcho, **opts.__dict__)
    server.start_server()