18 lines
534 B
Python
18 lines
534 B
Python
|
|
||
|
import socket
|
||
|
|
||
|
HOST = "127.0.0.1" # Standard loopback interface address (localhost)
|
||
|
PORT = 2000 # Port to listen on (non-privileged ports are > 1023)
|
||
|
|
||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||
|
s.bind((HOST, PORT))
|
||
|
s.listen()
|
||
|
while True:
|
||
|
conn, addr = s.accept()
|
||
|
with conn:
|
||
|
print(f"Connected by {addr}")
|
||
|
while True:
|
||
|
data = conn.recv(1024)
|
||
|
if not data:
|
||
|
break
|
||
|
print(f'{data.hex()} [{len(data)}]')
|