Compare commits
3 Commits
e251fcd8f1
...
470bc59ffd
| Author | SHA1 | Date | |
|---|---|---|---|
| 470bc59ffd | |||
| dafacf2f23 | |||
| b11ef28829 |
@@ -1,11 +1,13 @@
|
|||||||
import os
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import websockets
|
import os
|
||||||
|
|
||||||
import asyncudp
|
import asyncudp
|
||||||
|
import websockets
|
||||||
|
|
||||||
UDP_IP = os.getenv("UDP_IP", "127.0.0.1")
|
UDP_IP = os.getenv("UDP_IP", "127.0.0.1")
|
||||||
UDP_PORT = int(os.getenv("UDP_PORT", 12345))
|
UDP_PORT = int(os.getenv("UDP_PORT", 12345))
|
||||||
|
|
||||||
|
|
||||||
async def websocket_handler(websocket):
|
async def websocket_handler(websocket):
|
||||||
udp_socket = await asyncudp.create_socket(remote_addr=(UDP_IP, UDP_PORT))
|
udp_socket = await asyncudp.create_socket(remote_addr=(UDP_IP, UDP_PORT))
|
||||||
print("Received new connection from", websocket.remote_address)
|
print("Received new connection from", websocket.remote_address)
|
||||||
@@ -27,10 +29,13 @@ async def websocket_handler(websocket):
|
|||||||
task1.cancel()
|
task1.cancel()
|
||||||
udp_socket.close()
|
udp_socket.close()
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
print("Starting websockets server with target", UDP_IP, UDP_PORT)
|
||||||
async with websockets.serve(websocket_handler, "0.0.0.0", 80):
|
async with websockets.serve(websocket_handler, "0.0.0.0", 80):
|
||||||
print("WebSocket server started")
|
print("WebSocket server started")
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(3600)
|
await asyncio.sleep(3600)
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
services:
|
services:
|
||||||
ws2udp:
|
ws2udp:
|
||||||
|
image: git.danilkolesnikov.ru/danilko09/udp_over_ws
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: central.Dockerfile
|
dockerfile: central.Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
udp2ws:
|
||||||
|
image: git.danilkolesnikov.ru/danilko09/udp_over_ws:leaf
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: leaf.Dockerfile
|
||||||
|
ports:
|
||||||
|
- 5005:5005/udp
|
||||||
|
restart: always
|
||||||
|
|||||||
9
leaf.Dockerfile
Normal file
9
leaf.Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
FROM python:3.8-slim
|
||||||
|
|
||||||
|
EXPOSE 5005
|
||||||
|
WORKDIR /app
|
||||||
|
RUN pip install --no-cache-dir websockets
|
||||||
|
|
||||||
|
COPY leaf.py /app/
|
||||||
|
STOPSIGNAL SIGINT
|
||||||
|
ENTRYPOINT ["python", "-u", "leaf.py"]
|
||||||
Reference in New Issue
Block a user