diff options
Diffstat (limited to 'examples/echo_srv.py')
-rw-r--r-- | examples/echo_srv.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/echo_srv.py b/examples/echo_srv.py new file mode 100644 index 0000000..b3855eb --- /dev/null +++ b/examples/echo_srv.py @@ -0,0 +1,16 @@ +import socket + +HOST = '127.0.0.1' +PORT = 9095 + +with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind((HOST, PORT)) + s.listen() + conn, addr = s.accept() + with conn: + while True: + data = conn.recv(1024) + print('recvd: {} bytes'.format(len(data))) + if len(data) == 0: + break; + conn.sendall(data) |