Simple WebSocket client and server.
Client
------
The client can connect to a WebSocket server, and can send messages to it. Sent and received messages are logged in the browser window. Orthogonal to this sending and receiving of messages, is a heartbeat component that sends a 'ping' after the client has not sent any message (or ping) to the server for 1 second. When the client does not receive any message (or pong) from the server for 3 seconds, it decides that there is a timeout (server or network problem), and will stop sending pings until recovered.
run_client.html: open this page in browser to run the WebSocket demo client
client.xml: WebSocket client SCCD model. Compile with language=javascript and platform=eventloop.
client.js: generated code from client.xml, imported by run_client.html
Server
------
The server is very simple. It creates a Connection object for every incoming connection, and destroys this object when the connection is closed. The Connection object listens for incoming messages. Every incoming message is responded to asap:
- a 'ping' is responded to with a 'pong'
- a 'msg' is echoed.
Files:
run_server.py: Python script to run the WebSocket demo server
server.xml: WebSocket server SCCD model. Compile with language=python and platform=eventloop.
server.py: generated code from server.xml, imported by run_server.py