Created
June 6, 2018 14:55
-
-
Save johnmurch/01d30472702bdd31835c8a1b44bf9b63 to your computer and use it in GitHub Desktop.
Python Simple Socket Server
This file contains hidden or 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 | |
s = socket.socket() | |
host = "0.0.0.0" # REPLACE with IP of server | |
port = 12345 | |
s.connect((host, port)) | |
s.send("foo") | |
s.close() |
This file contains hidden or 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 | |
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