Created
April 10, 2015 17:23
-
-
Save Averroes/625eab7efd671f8d21f1 to your computer and use it in GitHub Desktop.
simple authentication of clients
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
| 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