pyrtma.web_manager.WebsocketServer

class WebsocketServer(host='127.0.0.1', port=0, loglevel=30, key=None, cert=None)[source]

Bases: ThreadingMixIn, TCPServer, API

A websocket server waiting for clients to connect.

Parameters:
  • port (int) – Port to bind to

  • host (str) – Hostname or IP to listen for connections. By default 127.0.0.1 is being used. To accept connections from any client, you should use 0.0.0.0.

  • loglevel – Logging level from logging module to use for logging. By default warnings and errors are being logged.

Properties:
clients(list): A list of connected clients. A client is a dictionary
like below.
{

‘id’ : id, ‘handler’ : handler, ‘address’ : (addr, port)

}

Methods

allow_new_connections

client_left

close_request

Called to clean up an individual request.

deny_new_connections

disconnect_clients_abruptly

disconnect_clients_gracefully

fileno

Return socket file number.

finish_request

Finish one request by instantiating RequestHandlerClass.

get_request

Get the request and client address from the socket.

handle_error

Handle an error gracefully.

handle_request

Handle one request, possibly blocking.

handle_timeout

Called if no new request arrives within self.timeout.

handler_to_client

message_received

new_client

process_request

Start a new thread to process the request.

process_request_thread

Same as in BaseServer but as a thread.

run_forever

send_message

send_message_to_all

serve_forever

Handle one request at a time until shutdown.

server_activate

Called by constructor to activate the server.

server_bind

Called by constructor to bind the socket.

server_close

Called to clean-up the server.

service_actions

Called by the serve_forever() loop.

set_fn_client_left

set_fn_message_received

set_fn_new_client

shutdown

Stops the serve_forever loop.

shutdown_abruptly

shutdown_gracefully

shutdown_request

Called to shutdown and close an individual request.

verify_request

Verify the request.

Attributes

address_family

allow_reuse_address

block_on_close

daemon_threads

request_queue_size

socket_type

timeout

close_request(request)

Called to clean up an individual request.

fileno()

Return socket file number.

Interface required by selector.

finish_request(request, client_address)

Finish one request by instantiating RequestHandlerClass.

get_request()

Get the request and client address from the socket.

May be overridden.

handle_error(request, client_address)

Handle an error gracefully. May be overridden.

The default is to print a traceback and continue.

handle_request()

Handle one request, possibly blocking.

Respects self.timeout.

handle_timeout()

Called if no new request arrives within self.timeout.

Overridden by ForkingMixIn.

process_request(request, client_address)

Start a new thread to process the request.

process_request_thread(request, client_address)

Same as in BaseServer but as a thread.

In addition, exception handling is done here.

serve_forever(poll_interval=0.5)

Handle one request at a time until shutdown.

Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.

server_activate()

Called by constructor to activate the server.

May be overridden.

server_bind()

Called by constructor to bind the socket.

May be overridden.

server_close()

Called to clean-up the server.

May be overridden.

service_actions()

Called by the serve_forever() loop.

May be overridden by a subclass / Mixin to implement any code that needs to be run during the loop.

shutdown()

Stops the serve_forever loop.

Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock.

shutdown_request(request)

Called to shutdown and close an individual request.

verify_request(request, client_address)

Verify the request. May be overridden.

Return True if we should proceed with this request.