Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import socket
  2. import threading
  3.  
  4. sock = socket.socket(socket.AF_INET, sock.SOCK_STREAM)
  5.  
  6. sock.bind(('0.0.0.0',10000))
  7.  
  8. sock.listen(1)
  9.  
  10. connections = []
  11.  
  12. def handler(c, a):
  13. global connections
  14. while True:
  15. data = c.recv(1024)
  16. for connection in connections
  17. connection.send(bytes(data))
  18. if no data:
  19. connections.remove(c)
  20. break
  21.  
  22. while True:
  23. c, a = sock.accept()
  24. cThread = threading.Thread(target=handler, args=(c,a))
  25. cThread.daemon = True
  26. cThread.start()
  27. connections.append(c)
  28. print(connections)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement