Skip to content

Instantly share code, notes, and snippets.

@johnmurch
Created June 6, 2018 14:55
Show Gist options
  • Save johnmurch/01d30472702bdd31835c8a1b44bf9b63 to your computer and use it in GitHub Desktop.
Save johnmurch/01d30472702bdd31835c8a1b44bf9b63 to your computer and use it in GitHub Desktop.
Python Simple Socket Server
import socket
s = socket.socket()
host = "0.0.0.0" # REPLACE with IP of server
port = 12345
s.connect((host, port))
s.send("foo")
s.close()
import socket
s = socket.socket()
host = ""
port = 12345
s.bind((host, port))
s.listen(5)
while True:
try:
clientsock, addr = s.accept()
except OSError:
continue
message = clientsock.recv(20)
#the code you want to run
print("doing %s" % message)
clientsock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment