Skip to content

Instantly share code, notes, and snippets.

@kengonakajima
Forked from limingzju/EchoServer.py
Created June 21, 2022 20:02
Show Gist options
  • Save kengonakajima/f0ffa8fb6864708f4a1e0738af7521c7 to your computer and use it in GitHub Desktop.
Save kengonakajima/f0ffa8fb6864708f4a1e0738af7521c7 to your computer and use it in GitHub Desktop.
A simple Python echo server, show how to write socket program use python.
# Echo server program
import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print('Connected by', addr)
while 1:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment