Advertisement
Guest User

ServerSide

a guest
Jun 8th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. # Owatch's Multi-Threading Username Sever. (Because the select module can suck it)
  2. from socket import *
  3. import threading
  4. import os
  5. import csv
  6. import sys
  7. # Defining Important Information
  8. User_List = []
  9. Connections_List = []
  10. # Making a thread class for each connection recieved.
  11. class Client(threading.Thread):
  12. def __init__(self,conn):
  13. super(Client, self).__init__()
  14. self.conn = conn
  15. self.username = self.conn.recv(1024).decode()
  16. if not any(user.username == self.username for user in User_List):
  17. print("New guy")
  18. # Add new guy to the list
  19. User_List.append(self)
  20.  
  21. # Get everyone's names
  22. current_userlist = [user.username for user in User_List]
  23.  
  24. # Send everyone's names to everyone
  25. for x in User_List:
  26.  
  27. conn.send(x.username.encode())
  28.  
  29.  
  30. U_HOST = input("Host: ")
  31. U_PORT = input("Port: ")
  32.  
  33. SS = socket(AF_INET,SOCK_STREAM)
  34. SS.bind((U_HOST,int(U_PORT)))
  35. SS.listen(2)
  36.  
  37.  
  38. while True:
  39. Connection,Address = SS.accept()
  40. Connections_List.append(Address)
  41. print("Connection Taken, and address added to list")
  42. CX = Client(Connection)
  43. CX.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement