Last active
March 15, 2017 16:35
-
-
Save Niximacco/eca60ba47c1bb217a37f97c04de2548a to your computer and use it in GitHub Desktop.
Starts a simple tcp server with python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Starts a simple tcp server with python. Run with
python Simple_TCP_Server.py <PORT>