How to use the websockify.websocket.WebSocketServer function in websockify

To help you get started, we’ve selected a few websockify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github novnc / websockify / tests / test_websocket.py View on Github external
def _get_websockserver(self, **kwargs):
        return websocket.WebSocketServer(listen_host='localhost',
                                         listen_port=80,
                                         key=self.tmpdir,
                                         web=self.tmpdir,
                                         record=self.tmpdir,
                                         **kwargs)
github novnc / websockify / tests / utf8-list.py View on Github external
#!/usr/bin/python

'''
Display UTF-8 encoding for 0-255.'''

import sys, os, socket, ssl, time, traceback
from select import select
sys.path.insert(0,os.path.join(os.path.dirname(__file__), ".."))
from websockify.websocket import WebSocketServer

if __name__ == '__main__':
    print "val: hybi_base64 | hybi_binary"
    for c in range(0, 256):
        hybi_base64 = WebSocketServer.encode_hybi(chr(c), opcode=1,
                base64=True)
        hybi_binary = WebSocketServer.encode_hybi(chr(c), opcode=2,
                base64=False)
        print "%d: %s | %s" % (c, repr(hybi_base64), repr(hybi_binary))
github novnc / websockify / tests / test_websocket.py View on Github external
def test_start_server_Exception(self):
        soc = self._get_websockserver(daemon=False, ssl_only=1, idle_timeout=1)
        self.stubs.Set(websocket.WebSocketServer, 'socket', self._mock_socket)
        self.stubs.Set(websocket.WebSocketServer, 'daemonize',
                       lambda *args, **kwargs: None)
        self.stubs.Set(select, 'select', self._mock_select_exception)
        self.assertEqual(None, soc.start_server())
github emscripten-core / emscripten / third_party / websockify / websockify / websocketproxy.py View on Github external
self.print_traffic(".>")


            if target in ins:
                # Receive target data, encode it and queue for client
                buf = target.recv(self.buffer_size)
                if len(buf) == 0:
                    if self.verbose:
                        self.log_message("%s:%s: Target closed connection",
                                self.server.target_host, self.server.target_port)
                    raise self.CClose(1000, "Target closed")

                cqueue.append(buf)
                self.print_traffic("{")

class WebSocketProxy(websocket.WebSocketServer):
    """
    Proxy traffic to and from a WebSockets client to a normal TCP
    socket server target. All traffic to/from the client is base64
    encoded/decoded to allow binary data to be sent/received to/from
    the target.
    """

    buffer_size = 65536

    def __init__(self, RequestHandlerClass=ProxyRequestHandler, *args, **kwargs):
        # Save off proxy specific options
        self.target_host    = kwargs.pop('target_host', None)
        self.target_port    = kwargs.pop('target_port', None)
        self.wrap_cmd       = kwargs.pop('wrap_cmd', None)
        self.wrap_mode      = kwargs.pop('wrap_mode', None)
        self.unix_target    = kwargs.pop('unix_target', None)
github jamesacampbell / python-examples / websockify-example.py View on Github external
self.print_traffic(".>")

            if target in ins:
                # Receive target data, encode it and queue for client
                buf = target.recv(self.buffer_size)
                if len(buf) == 0:
                    if self.verbose:
                        self.log_message("%s:%s: Target closed connection",
                                         self.server.target_host, self.server.target_port)
                    raise self.CClose(1000, "Target closed")

                cqueue.append(buf)
                self.print_traffic("{")


class WebSocketProxy(websocket.WebSocketServer):
    """
    Proxy traffic to and from a WebSockets client to a normal TCP
    socket server target. All traffic to/from the client is base64
    encoded/decoded to allow binary data to be sent/received to/from
    the target.
    """

    buffer_size = 65536

    def __init__(self, RequestHandlerClass=ProxyRequestHandler, *args, **kwargs):
        # Save off proxy specific options
        self.target_host = kwargs.pop('target_host', None)
        self.target_port = kwargs.pop('target_port', None)
        self.wrap_cmd = kwargs.pop('wrap_cmd', None)
        self.wrap_mode = kwargs.pop('wrap_mode', None)
        self.unix_target = kwargs.pop('unix_target', None)