mirror of
				https://github.com/espressif/esp-idf.git
				synced 2025-11-03 22:08:28 +00:00 
			
		
		
		
	websocket: Updated Kconfig to use 'echo.websocket.events' echo server
Updated README to show how to run websocket echo server using Flask Merges https://github.com/espressif/esp-idf/pull/8262
This commit is contained in:
		@@ -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
 | 
			
		||||
@@ -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)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user