Komplett WebSocket Server soweit fertig

This commit is contained in:
Eduard Wisch 2025-03-16 18:33:48 +01:00
parent f63cb8680c
commit b6965971ac
4 changed files with 53 additions and 0 deletions

4
__main__.py Normal file
View file

@ -0,0 +1,4 @@
from app.main_server import Server
if __name__ == "__main__":
obj_server = Server()

30
app/main_server.py Normal file
View file

@ -0,0 +1,30 @@
import websockets
import asyncio
class Server:
def __init__(self):
self.ip = "0.0.0.0"
self.port = 8000
try:
asyncio.run(self.start())
except KeyboardInterrupt:
print("Server sagt: Server wurde beendet.")
@staticmethod
async def handle_client(websocket):
print("Server sagt: Client verbunden")
try:
async for message in websocket:
print(f"Server hat Empfangen: {message}")
response = f"Server antwortet: {message.upper()}"
await websocket.send(response)
except websockets.exceptions.ConnectionClosed:
print("Server sagt: Client getrennt")
async def start(self):
server = await websockets.serve(self.handle_client, self.ip, self.port)
print(f"Websocket Server läuft auf IP: {self.ip} Port: {self.port}")
await server.wait_closed()

View file

@ -0,0 +1,9 @@
#!/bin/bash
SERVER="ws://localhost:8000/"
for FILE in "$@"; do
JSON=$(printf '{"data_path: "%s"}' "$FILE")
echo "$JSON" | websocat "$SERVER"
done

View file

@ -0,0 +1,10 @@
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=video/*
Actions=sendToWebSocket
[Desktop Action sendToWebSocket]
Name=Video to New Server
Exec=/home/data/.local/share/kio/servicemenus/send.path.sh %F
Icon=video-x-generic