Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 17:23
Show Gist options
  • Select an option

  • Save Averroes/625eab7efd671f8d21f1 to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/625eab7efd671f8d21f1 to your computer and use it in GitHub Desktop.
simple authentication of clients
from socket import socket, AF_INET, SOCK_STREAM
from auth import server_authenticate
secret_key = b'peekaboo'
def echo_handler(client_sock):
if not server_authenticate(client_sock, secret_key):
client_sock.close()
return
while True:
msg = client_sock.recv(8192)
if not msg:
break
client_sock.sendall(msg)
def echo_server(address):
s = socket(AF_INET, SOCK_STREAM)
s.bind(address)
s.listen(5)
while True:
c,a = s.accept()
echo_handler(c)
print('Echo server running on port 18000')
echo_server(('', 18000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment