Skip to content

Instantly share code, notes, and snippets.

@AnthonyNixon
Last active March 15, 2017 16:35
Show Gist options
  • Save AnthonyNixon/eca60ba47c1bb217a37f97c04de2548a to your computer and use it in GitHub Desktop.
Save AnthonyNixon/eca60ba47c1bb217a37f97c04de2548a to your computer and use it in GitHub Desktop.
Starts a simple tcp server with python.
import socket
import sys
HOST = '0.0.0.0' # Symbolic name meaning the local host
PORT = int(sys.argv[1]) # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
print 'Listening to ' + HOST + ':' + str(PORT)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data:
break
conn.send(data)
conn.close()
@AnthonyNixon
Copy link
Author

Starts a simple tcp server with python. Run with python Simple_TCP_Server.py <PORT>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment