Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
# Websockets
|
||||
|
||||
## Introduction
|
||||
### Why are we going to use websockets?
|
||||
With websockets you can establish a connection between the client and the server, and both can send data fast to each other. This is useful for real-time applications like for our project to plot live graphs of the data we are collecting from the sensors.
|
||||
|
||||
### How to use websockets
|
||||
There are different languages to serve websockets with, but we are going to use Python with the library `websockets`. This library is easy to use and has a lot of documentation.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Sources:
|
||||
* https://websockets.readthedocs.io/en/stable/index.html
|
21
server/Websocket.py
Normal file
21
server/Websocket.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import websockets;
|
||||
import asyncio;
|
||||
|
||||
|
||||
async def handler(websocket):
|
||||
while True:
|
||||
#Save the incoming message in variable message.
|
||||
message = await websocket.recv()
|
||||
print(message)
|
||||
|
||||
|
||||
async def main():
|
||||
async with websockets.serve(handler, "145.92.8.114" , 8001):
|
||||
await asyncio.Future() # run forever
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
|
||||
#https://websockets.readthedocs.io/en/stable/reference/sync/server.html#websockets.sync.server.serve
|
Reference in New Issue
Block a user