Files
phpy/examples/socket/server.py
2024-02-18 13:30:39 +08:00

17 lines
362 B
Python

import socket
HOST = "127.0.0.1"
PORT = 5432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)