Created
August 1, 2016 13:50
-
-
Save nathantowell/9965d085029c1c6b67579a480f9c3e9c to your computer and use it in GitHub Desktop.
A quick use of sockets in python 3
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 | |
s = socket.socket() | |
host = socket.gethostname() | |
port = 6789 | |
s.connect((host, port)) | |
print(s.recv(1024).decode()) | |
s.close |
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 | |
s = socket.socket() | |
host = socket.gethostname() | |
port = 6789 | |
s.bind((host, port)) | |
s.listen(5) | |
while True: | |
c, addr = s.accept() | |
print("Got connection from", addr) | |
c.send("Thank you for connecting".encode()) | |
c.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment