Skip to content

Instantly share code, notes, and snippets.

@nathantowell
Created August 1, 2016 13:50
Show Gist options
  • Save nathantowell/9965d085029c1c6b67579a480f9c3e9c to your computer and use it in GitHub Desktop.
Save nathantowell/9965d085029c1c6b67579a480f9c3e9c to your computer and use it in GitHub Desktop.
A quick use of sockets in python 3
import socket
s = socket.socket()
host = socket.gethostname()
port = 6789
s.connect((host, port))
print(s.recv(1024).decode())
s.close
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