-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
24 lines (20 loc) · 703 Bytes
/
Copy pathserver.py
File metadata and controls
24 lines (20 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import asyncio
import websockets
import os
# Altere o IP e porta conforme necessário
# IP = ""
# PORTA = 1234
async def receber_arquivo(websocket):
print("Aguardando arquivo...")
nome_arquivo = await websocket.recv()
print(f"Recebendo arquivo: {nome_arquivo}")
conteudo = await websocket.recv()
with open(f"recebido_{nome_arquivo}", "w") as f:
f.write(conteudo)
print(f"Arquivo salvo como recebido_{nome_arquivo}")
async def main():
async with websockets.serve(receber_arquivo, IP, PORTA):
print(f"Servidor WebSocket escutando em ws://{IP}:{PORTA}")
await asyncio.Future() # Roda para sempre
if __name__ == "__main__":
asyncio.run(main())