Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This is just an example not prepared to warn other clients when one leave the chatroom and not even when it's empty
- #just connect and talk. It's for an article at my wordpress.
- #Check the complete aticle at http://obernardovieira.byethost18.com
- #client side here http://pastebin.com/SXnqHTyU
- # Echo server program
- import socket
- from threading import Thread
- all_conns = []
- def sendToAll(data):
- for conn in all_conns:
- conn.sendall(data)
- def talkToClient(conn, addr):
- print 'Connected by', addr
- while 1:
- data = conn.recv(1024)
- if not data: break
- sendToAll(data);
- conn.close()
- HOST = 'localhost' # Symbolic name meaning all available interfaces
- PORT = 50007 # Arbitrary non-privileged port
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.bind((HOST, PORT))
- s.listen(1)
- while 1:
- conn, addr = s.accept()
- all_conns.append(conn)
- Thread(target=talkToClient, args=(conn,addr,)).start()
Add Comment
Please, Sign In to add comment