Last active
August 29, 2015 14:26
-
-
Save psyomn/743c6608b6441eb78514 to your computer and use it in GitHub Desktop.
crappy insecure python chat 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 threading | |
| from multiprocessing.connection import Listener | |
| from multiprocessing.connection import Client | |
| from array import array | |
| def listen(): | |
| address = ('', 50000) | |
| listener = Listener(address) | |
| conn = listener.accept() | |
| while True: | |
| print conn.recv_bytes() | |
| try: | |
| t = threading.Thread(target=listen) | |
| t.start() | |
| cmd = "default" | |
| print "username: ", | |
| username = raw_input() | |
| print "host: ", | |
| host = raw_input() | |
| print "port: ", | |
| port = raw_input() | |
| address = (host, int(port)) | |
| client = Client(address) | |
| while cmd != '/end': | |
| cmd = raw_input() | |
| client.send_bytes(username + ': ' + cmd) | |
| except KeyboardInterrupt: | |
| print "Listener exited." | |
| exit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment