circuitpython/tests/circuitpython-manual/socketpool/client/host-server.py

28 lines
615 B
Python
Raw Normal View History

2021-02-11 17:36:40 -05:00
#!/usr/bin/env python3
import socket
TIMEOUT = 10
HOST = "192.168.10.179"
PORT = 5000
print("Create Socket")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(TIMEOUT)
s.bind((HOST, PORT))
s.listen()
print("Accepting connections")
while True:
try:
conn, addr = s.accept()
break
except BlockingIOError:
pass
with conn:
s.settimeout(TIMEOUT)
2021-03-15 09:57:36 -04:00
print("Connected by", addr)
2021-02-11 17:36:40 -05:00
data = conn.recv(128)
print("got: " + str(data))
conn.sendall(data)
2021-02-18 16:26:14 -05:00
print("sent: " + str(data))