How to use the websockify.websockifyserver.WebSockifyRequestHandler 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 / load.py View on Github external
import sys, os, select, random, time, optparse, logging
sys.path.insert(0,os.path.join(os.path.dirname(__file__), ".."))
from websockify.websockifyserver import WebSockifyServer, WebSockifyRequestHandler

class WebSocketLoadServer(WebSockifyServer):

    recv_cnt = 0
    send_cnt = 0

    def __init__(self, *args, **kwargs):
        self.delay = kwargs.pop('delay')

        WebSockifyServer.__init__(self, *args, **kwargs)


class WebSocketLoad(WebSockifyRequestHandler):

    max_packet_size = 10000

    def new_websocket_client(self):
        print "Prepopulating random array"
        self.rand_array = []
        for i in range(0, self.max_packet_size):
            self.rand_array.append(random.randint(0, 9))

        self.errors = 0
        self.send_cnt = 0
        self.recv_cnt = 0

        self.responder(self.request)

        print "accumulated errors:", self.errors
github novnc / websockify / tests / echo.py View on Github external
'''
A WebSocket server that echos back whatever it receives from the client.
Copyright 2010 Joel Martin
Licensed under LGPL version 3 (see docs/LICENSE.LGPL-3)

You can make a cert/key with openssl using:
openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem
as taken from http://docs.python.org/dev/library/ssl.html#certificates
'''

import os, sys, select, optparse, logging
sys.path.insert(0,os.path.join(os.path.dirname(__file__), ".."))
from websockify.websockifyserver import WebSockifyServer, WebSockifyRequestHandler

class WebSocketEcho(WebSockifyRequestHandler):
    """
    WebSockets server that echos back whatever is received from the
    client.  """
    buffer_size = 8096

    def new_websocket_client(self):
        """
        Echo back whatever is received.
        """

        cqueue = []
        c_pend = 0
        cpartial = ""
        rlist = [self.request]

        while True:
github novnc / websockify / tests / test_websockifyserver.py View on Github external
    def _get_server(self, handler_class=websockifyserver.WebSockifyRequestHandler,
                    **kwargs):
        web = kwargs.pop('web', self.tmpdir)
        return websockifyserver.WebSockifyServer(
            handler_class, listen_host='localhost',
            listen_port=80, key=self.tmpdir, web=web,
            record=self.tmpdir, daemon=False, ssl_only=0, idle_timeout=1,
            **kwargs)
github novnc / websockify / tests / test_websockifyserver.py View on Github external
def test_normal_get_with_only_upgrade_returns_error(self):
        server = self._get_server(web=None)
        handler = websockifyserver.WebSockifyRequestHandler(
            FakeSocket('GET /tmp.txt HTTP/1.1'), '127.0.0.1', server)

        def fake_send_response(self, code, message=None):
            self.last_code = code

        self.stubs.Set(BaseHTTPRequestHandler, 'send_response',
                       fake_send_response)

        handler.do_GET()
        self.assertEqual(handler.last_code, 405)
github novnc / websockify / tests / test_websockifyserver.py View on Github external
def test_list_dir_with_file_only_returns_error(self):
        server = self._get_server(file_only=True)
        handler = websockifyserver.WebSockifyRequestHandler(
            FakeSocket('GET / HTTP/1.1'), '127.0.0.1', server)

        def fake_send_response(self, code, message=None):
            self.last_code = code

        self.stubs.Set(BaseHTTPRequestHandler, 'send_response',
                       fake_send_response)

        handler.path = '/'
        handler.do_GET()
        self.assertEqual(handler.last_code, 404)
github anthony-mills / raspberrypi-carputer / websockify / websockify / websocketproxy.py View on Github external
import signal, socket, optparse, time, os, sys, subprocess, logging, errno
try:    from socketserver import ForkingMixIn
except: from SocketServer import ForkingMixIn
try:    from http.server import HTTPServer
except: from BaseHTTPServer import HTTPServer
import select
from websockify import websockifyserver
from websockify import auth_plugins as auth
try:
    from urllib.parse import parse_qs, urlparse
except:
    from cgi import parse_qs
    from urlparse import urlparse

class ProxyRequestHandler(websockifyserver.WebSockifyRequestHandler):

    buffer_size = 65536

    traffic_legend = """
Traffic Legend:
    }  - Client receive
    }. - Client receive partial
    {  - Target receive

    >  - Target send
    >. - Target send partial
    <  - Client send
    <. - Client send partial
"""
    
    def send_auth_error(self, ex):
github fcwu / docker-ubuntu-vnc-desktop / image / usr / local / lib / novnc / utils / websockify / websockify / websocketproxy.py View on Github external
import signal, socket, optparse, time, os, sys, subprocess, logging, errno
try:    from socketserver import ForkingMixIn
except: from SocketServer import ForkingMixIn
try:    from http.server import HTTPServer
except: from BaseHTTPServer import HTTPServer
import select
from websockify import websockifyserver
from websockify import auth_plugins as auth
try:
    from urllib.parse import parse_qs, urlparse
except:
    from cgi import parse_qs
    from urlparse import urlparse

class ProxyRequestHandler(websockifyserver.WebSockifyRequestHandler):

    buffer_size = 65536

    traffic_legend = """
Traffic Legend:
    }  - Client receive
    }. - Client receive partial
    {  - Target receive

    >  - Target send
    >. - Target send partial
    <  - Client send
    <. - Client send partial
"""
    
    def send_auth_error(self, ex):
github novnc / websockify / websockify / websocketproxy.py View on Github external
try:
    from http.server import HTTPServer
except ImportError:
    from BaseHTTPServer import HTTPServer

import select
from websockify import websockifyserver
from websockify import auth_plugins as auth
try:
    from urllib.parse import parse_qs, urlparse
except ImportError:
    from cgi import parse_qs
    from urlparse import urlparse

class ProxyRequestHandler(websockifyserver.WebSockifyRequestHandler):

    buffer_size = 65536

    traffic_legend = """
Traffic Legend:
    }  - Client receive
    }. - Client receive partial
    {  - Target receive

    >  - Target send
    >. - Target send partial
    <  - Client send
    <. - Client send partial
"""
    
    def send_auth_error(self, ex):