Skip to content

Commit

Permalink
Merge branch 'bugfix/websocket_example_echo_server_v4.3' into 'releas…
Browse files Browse the repository at this point in the history
…e/v4.3'

websocket: Updated Kconfig to use 'echo.websocket.events' echo server(v4.3)

See merge request espressif/esp-idf!17605
  • Loading branch information
david-cermak committed Apr 4, 2022
2 parents 4efc516 + 1457686 commit d756745
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion examples/protocols/websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ I (4472) tcpip_adapter: eth ip: 192.168.2.137, mask: 255.255.255.0, gw: 192.168.
I (4472) example_connect: Connected to Ethernet
I (4472) example_connect: IPv4 address: 192.168.2.137
I (4472) example_connect: IPv6 address: fe80:0000:0000:0000:bedd:c2ff:fed4:a92b
I (4482) WEBSOCKET: Connecting to ws://echo.websocket.org...
I (4482) WEBSOCKET: Connecting to ws://echo.websocket.events...
I (5012) WEBSOCKET: WEBSOCKET_EVENT_CONNECTED
I (5492) WEBSOCKET: Sending hello 0000
I (6052) WEBSOCKET: WEBSOCKET_EVENT_DATA
Expand All @@ -56,3 +56,35 @@ W (9162) WEBSOCKET: Received=hello 0003
```


## Python Flask echo server

By default, the `ws://echo.websocket.events` endpoint is used. You can setup a Python websocket echo server locally and try the `ws://<your-ip>:5000` endpoint. To do this, install Flask-sock Python package

```
pip install flask-sock
```

and start a Flask websocket echo server locally by executing the following Python code:

```python
from flask import Flask
from flask_sock import Sock

app = Flask(__name__)
sock = Sock(app)


@sock.route('/')
def echo(ws):
while True:
data = ws.receive()
ws.send(data)


if __name__ == '__main__':
# To run your Flask + WebSocket server in production you can use Gunicorn:
# gunicorn -b 0.0.0.0:5000 --workers 4 --threads 100 module:app
app.run(host="0.0.0.0", debug=True)
```

2 changes: 1 addition & 1 deletion examples/protocols/websocket/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ menu "Example Configuration"
config WEBSOCKET_URI
string "Websocket endpoint URI"
depends on WEBSOCKET_URI_FROM_STRING
default "ws://echo.websocket.org"
default "ws://echo.websocket.events"
help
URL of websocket endpoint this example connects to and sends echo

Expand Down

0 comments on commit d756745

Please sign in to comment.