Komplett WebSocket Server soweit fertig
This commit is contained in:
parent
f63cb8680c
commit
b6965971ac
4 changed files with 53 additions and 0 deletions
4
__main__.py
Normal file
4
__main__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from app.main_server import Server
|
||||
|
||||
if __name__ == "__main__":
|
||||
obj_server = Server()
|
||||
30
app/main_server.py
Normal file
30
app/main_server.py
Normal 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()
|
||||
9
kde_context_plugin/share/kio/servicemenus/send.path.sh
Executable file
9
kde_context_plugin/share/kio/servicemenus/send.path.sh
Executable 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
|
||||
10
kde_context_plugin/share/kio/servicemenus/videos_to_new_server.desktop
Executable file
10
kde_context_plugin/share/kio/servicemenus/videos_to_new_server.desktop
Executable 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
|
||||
Loading…
Reference in a new issue