Skip to content

Instantly share code, notes, and snippets.

@Chandler
Created December 21, 2017 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chandler/db617a65f35926dbdf65a2200c6eb762 to your computer and use it in GitHub Desktop.
Save Chandler/db617a65f35926dbdf65a2200c6eb762 to your computer and use it in GitHub Desktop.
Echo Server Client
# Echo client program
import socket
HOST = '127.0.0.1' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)
# Echo server program
import socket
HOST = '' # Symbolic name meaning the local host
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.send(data)
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment