This WebSocket backend performs the following actions:
- Echoes whatever message is sent in a streaming format with a 0.1-second delay.
- Echoes the message in reverse in a streaming format with a 0.1-second delay.
- Counts the number of times the last character is repeated in the message (excluding the last character) and returns this count.
-
Python 3.x version
-
websocketslibrary -
asynciolibrary -
pip install websockets asyncio
-
pip install nest_asyncio
- Set Up Your Development Environment
- Create the WebSocket Backend with appropriate file name(eg.websocket_server.py)
- Connect to the WebSocket server at 'ws://localhost:8765'.
- Open WebSocketking.com and Connent the sever
- Write message in input area avaible in WebSocketKing and Press and Send
- Create websocket_client.py file to test the WebSocket backend
{ "action": "echo", "content": "Hello" }
{ "message": "H" } { "message": "e" } { "message": "l" } { "message": "l" } { "message": "o"
}
{ "action": "reverse", "content": "Hello" }
{ "message": "o" } { "message": "l" } { "message": "l" } { "message": "e" } { "message": "H" }
{ "action": "count_last_char", "content": "The quick brown fox jumped over the lazy dog o" }
{ "message": "Last character: o, Count: 4" }
- Open Terminal and Run websocket_server.py
- Open another terminal and run websocket_client.py(only for testing You can directly give input by opening WebSocketKing and by connecting server)