Skip to content

Instantly share code, notes, and snippets.

@psyomn
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save psyomn/743c6608b6441eb78514 to your computer and use it in GitHub Desktop.

Select an option

Save psyomn/743c6608b6441eb78514 to your computer and use it in GitHub Desktop.
crappy insecure python chat server
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