Guest User

Untitled

a guest
Mar 29th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. from core.module import *
  2.  
  3. try:
  4.     soc = socket.socket()
  5.     host = "localhost"
  6.     port = 5050
  7.     soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  8.     soc.bind((host, port))
  9.     soc.listen(30)
  10.     client=[]
  11.     def main():
  12.         while 1:
  13.             conn, addr = soc.accept()
  14.             print(addr)
  15.             msg = conn.recv(1024)
  16.             if  addr not in client :
  17.                 client.append(addr)
  18.             for clients in client :
  19.                 if clients == addr :
  20.                     print('ok')
  21.                     continue
  22.                 else:
  23.                     message_to_send = msg
  24.                     conn.sendto(len(message_to_send).to_bytes(2, byteorder='big'), clients)
  25.                     conn.sendto(message_to_send, clients)
  26.    
  27.     def commands():
  28.         while 1:
  29.             command=input(f'{R}root@{DC}localhost{W}~#: ')
  30.             if command=='close':
  31.                 print(f'{R}Server close')
  32.                 soc.close()
  33.     main=Thread (target=main)
  34.     commands=Thread (target=commands)
  35.     commands.start()
  36.     main.start()
  37. except Exception as e:
  38.     print(e)
  39.     sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment