Package archipelagentvirtualmachinevnc :: Module websocket :: Class WebSocketServer
[hide private]
[frames] | no frames]

Class WebSocketServer

source code

object --+
         |
        WebSocketServer

WebSockets server class. Must be sub-classed with new_client method definition.

Nested Classes [hide private]
  EClose
  CClose
Instance Methods [hide private]
 
__init__(self, listen_host='', listen_port=None, source_is_ipv6=False, verbose=False, cert='', key='', ssl_only=None, daemon=False, record='', web='', run_once=False, timeout=0, idle_timeout=0)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
traffic(self, token=".")
Show traffic flow in verbose mode.
source code
 
msg(self, msg)
Output message with handler_id prefix.
source code
 
vmsg(self, msg)
Same as msg() but only if verbose.
source code
 
send_frames(self, bufs=None)
Encode and send WebSocket frames.
source code
 
recv_frames(self)
Receive and decode WebSocket frames.
source code
 
send_close(self, code=1000, reason='')
Send a WebSocket orderly close frame.
source code
 
do_websocket_handshake(self, headers, path) source code
 
do_handshake(self, sock, address)
do_handshake does the following: - Peek at the first few bytes from the socket.
source code
 
started(self)
Called after WebSockets startup
source code
 
poll(self)
Run periodically while waiting for connections.
source code
 
fallback_SIGCHLD(self, sig, stack) source code
 
do_SIGINT(self, sig, stack) source code
 
top_new_client(self, startsock, address)
Do something with a WebSockets client connection.
source code
 
new_client(self)
Do something with a WebSockets client connection.
source code
 
stop_server(self)
Stops the server if running
source code
 
start_server(self)
Daemonize if requested.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
socket(host, port=None, connect=False, prefer_ipv6=False, unix_socket=None, use_ssl=False)
Resolve a host (and optional port) to an IPv4 or IPv6 address.
source code
 
daemonize(keepfd=None, chdir='/') source code
 
unmask(buf, f) source code
 
encode_hybi(buf, opcode, base64=False)
Encode a HyBi style WebSocket frame.
source code
 
decode_hybi(buf, base64=False)
Decode HyBi style WebSocket packets.
source code
 
encode_hixie(buf) source code
 
decode_hixie(buf) source code
 
gen_md5(keys)
Generate hash value for WebSockets hixie-76.
source code
Class Variables [hide private]
  buffer_size = 65536
  server_handshake_hixie = """HTTP/1.1 101 Web Socket Protocol H...
  server_handshake_hybi = """HTTP/1.1 101 Switching Protocol...
  GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
  policy_response = """<cross-domain-policy><allow-access-from d...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, listen_host='', listen_port=None, source_is_ipv6=False, verbose=False, cert='', key='', ssl_only=None, daemon=False, record='', web='', run_once=False, timeout=0, idle_timeout=0)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

socket(host, port=None, connect=False, prefer_ipv6=False, unix_socket=None, use_ssl=False)
Static Method

source code 

Resolve a host (and optional port) to an IPv4 or IPv6 address. Create a socket. Bind to it if listen is set, otherwise connect to it. Return the socket.

encode_hybi(buf, opcode, base64=False)
Static Method

source code 
Encode a HyBi style WebSocket frame.
Optional opcode:
    0x0 - continuation
    0x1 - text frame (base64 encode buf)
    0x2 - binary frame (use raw buf)
    0x8 - connection close
    0x9 - ping
    0xA - pong

decode_hybi(buf, base64=False)
Static Method

source code 
Decode HyBi style WebSocket packets.
Returns:
    {'fin'          : 0_or_1,
     'opcode'       : number,
     'mask'         : 32_bit_number,
     'hlen'         : header_bytes_number,
     'length'       : payload_bytes_number,
     'payload'      : decoded_buffer,
     'left'         : bytes_left_number,
     'close_code'   : number,
     'close_reason' : string}

send_frames(self, bufs=None)

source code 

Encode and send WebSocket frames. Any frames already queued will be sent first. If buf is not set then only queued frames will be sent. Returns the number of pending frames that could not be fully sent. If returned pending frames is greater than 0, then the caller should call again when the socket is ready.

recv_frames(self)

source code 
Receive and decode WebSocket frames.

Returns:
    (bufs_list, closed_string)

do_handshake(self, sock, address)

source code 

do_handshake does the following:
- Peek at the first few bytes from the socket.
- If the connection is Flash policy request then answer it,
  close the socket and return.
- If the connection is an HTTPS/SSL/TLS connection then SSL
  wrap the socket.
- Read from the (possibly wrapped) socket.
- If we have received a HTTP GET request and the webserver
  functionality is enabled, answer it, close the socket and
  return.
- Assume we have a WebSockets connection, parse the client
  handshake data.
- Send a WebSockets handshake server response.
- Return the socket for this WebSocket client.

start_server(self)

source code 

Daemonize if requested. Listen for for connections. Run do_handshake() method for each connection. If the connection is a WebSockets client then call new_client() method (which must be overridden) for each new client connection.


Class Variable Details [hide private]

server_handshake_hixie

Value:
"""HTTP/1.1 101 Web Socket Protocol Handshake\r
Upgrade: WebSocket\r
Connection: Upgrade\r
%sWebSocket-Origin: %s\r
%sWebSocket-Location: %s://%s%s\r
"""

server_handshake_hybi

Value:
"""HTTP/1.1 101 Switching Protocols\r
Upgrade: websocket\r
Connection: Upgrade\r
Sec-WebSocket-Accept: %s\r
"""

policy_response

Value:
"""<cross-domain-policy><allow-access-from domain="*" to-ports="*" /><\
/cross-domain-policy>\n"""