Skip to content

Latest commit

 

History

History
82 lines (53 loc) · 1.9 KB

README.adoc

File metadata and controls

82 lines (53 loc) · 1.9 KB

Websocket Echo Server in Python

  1. Start the Server (see below for multiple options).

  2. Connect with a Client (in another shell).

Server

Run on localhost in Python

Python 3 required.

python3 -m pip install -r requirements.txt

python3 wsecho.py

Run on localhost in Docker

docker build -f Dockerfile -t websocket-echo-server-python .

docker run -i --rm -p 8080:8080 websocket-echo-server-python

Run on Google Cloud Run

Run on Google Cloud

Note the URL displayed after Your application is now live here.

Client

Download Python WebSocket Client

Python 3 required for websocket_client.

wget https://github.com/websocket-client/websocket-client/raw/master/bin/wsdump.py

Connect with Python WebSocket Client

# Server running on localhost:

python3 wsdump.py ws://127.0.0.1:8080/websocket
# Now enter texts and press RETURN.
# The texts are echoed by the server.


# Server running on Google Cloud Run:

python3 wsdump.py wss://websocket-echo-server-python-xxxxxxxxxx-xx.x.run.app/websocket
# Use the hostname that was displayed in Cloud Shell when deploying the server app to Cloud Run.

Dart WebSocket Client

Dart required.

dart pub get

# echo.websocket.org is used by default:
dart run wsclient.dart

# Server running on localhost:
dart run wsclient.dart --url ws://localhost:8080/websocket

# Server running on Google Cloud Run:
dart run wsclient.dart --url wss://websocket-echo-server-python-xxxxxxxxxx-xx.x.run.app/websocket