coopihc.bundle.WsServer.WsServer
- class WsServer(bundle, taskwrapper, address='localhost', port=4000)[source]
Bases:
object
WebSocket Server for Bundle
A Websocket server that handles a bundle with an external task that communicates with that server.
- Parameters
bundle (
Bundle
) – the bundle to servetaskwrapper (
PipeTaskWrapper
) – Task wrapperaddress (str, optional) – server address, defaults to “localhost”
port (int, optional) – port number, defaults to 4000
Methods
On websocket connection, starts a new userTrial in a new Process.
When messages from websocket are received, send them over the pipe
Check pipe for messages to send to websocket.
Look for messages to send from the Bundle.
Keep track of clients.
Start the server
- async bundlehandler(websocket, path, bundle, taskwrapper)[source]
On websocket connection, starts a new userTrial in a new Process. Then starts async listeners for sending and recieving messages.
- Parameters
websocket (string) – address
path (int) – portnumber
bundle (
Bundle
) – the bundle to servetaskwrapper (
PipeTaskWrapper
) – Task wrapper
- async consumer_handler(websocket, pipe)[source]
When messages from websocket are received, send them over the pipe
- Parameters
websocket (string) – address
pipe (
Pipe
) – Pipe through which messages are sent
- async producer(websocket, pipe)[source]
Check pipe for messages to send to websocket. If the process is done, send final message to websocket and return True to tell calling functions that the process is complete.
- Parameters
websocket (string) – address
pipe (
Pipe
) – Pipe through which messages are sent
- Returns
[description]
- Return type
[type]
- async producer_handler(websocket, pipe)[source]
Look for messages to send from the Bundle. asyncio.sleep() is required to make this non-blocking default sleep time is (0.01) which creates a maximum framerate of just under 100 frames/s. For faster framerates decrease sleep time however be aware that this will affect the ability of the consumer_handler function to keep up with messages from the websocket and may cause poor performance if the web-client is sending a high volume of messages.
- Parameters
websocket (string) – address
pipe (
Pipe
) – Pipe through which messages are sent