ESP8266-Websocket
ESP8266-Websocket copied to clipboard
How to create own websocket server?
Hi, this is very interesting websocket client. It is working when connecting to echo.websocket.org but if change host url to my url and copy the same echo.websocket into index.html it does not work. Any help would be appreciated.
Where did you find the code? The current example is with another board... :/
Below is simple websocket server wrote with Python 3.6 (Using flask
Flask-Sockets
), you can preference:
from flask import Flask
from flask_sockets import Sockets
app = Flask(__name__)
sockets = Sockets(app)
@sockets.route('/')
def echo_socket(ws):
while not ws.closed:
message = ws.receive()
ws.send(message)
@app.route('/')
def hello():
return 'Server working!'
if __name__ == "__main__":
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
server = pywsgi.WSGIServer(('', 5000), application=app, handler_class=WebSocketHandler)
server.serve_forever()
Now you can start by save file as app.py
then run from terminal: python3.6 app.py
.
First, connect to: ws://127.0.0.1:500/
then try to _websocketInstance.sendData("Hello, world!")
, you will received Hello, world!
from _websocketInstance.getData(_receivedDataStringInstance)
!