wooly-vault/solutions/1.py

31 lines
556 B
Python
Raw Permalink Normal View History

2024-09-06 23:55:31 +02:00
from io import TextIOWrapper
import socket
REMOTE = "127.0.0.1"
PORT = 1337
def main() -> int:
s = socket.socket()
s.connect((REMOTE, PORT))
sf: TextIOWrapper = s.makefile('rw')
_response: str = recv(sf)
sf.close()
return 0
def send(sf: TextIOWrapper, msg: str) -> int:
print(f"> {msg}")
sent: int = sf.write(f"{msg}\n")
sf.flush()
return sent
def recv(sf: TextIOWrapper) -> str:
response = sf.readline().strip()
print(f"< {response}")
return response
if __name__ == "__main__":
exit(main())