Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from core.module import *
- try:
- soc = socket.socket()
- host = "localhost"
- port = 5050
- soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- soc.bind((host, port))
- soc.listen(30)
- client=[]
- def main():
- while 1:
- conn, addr = soc.accept()
- print(addr)
- msg = conn.recv(1024)
- if addr not in client :
- client.append(addr)
- for clients in client :
- if clients == addr :
- print('ok')
- continue
- else:
- message_to_send = msg
- conn.sendto(len(message_to_send).to_bytes(2, byteorder='big'), clients)
- conn.sendto(message_to_send, clients)
- def commands():
- while 1:
- command=input(f'{R}root@{DC}localhost{W}~#: ')
- if command=='close':
- print(f'{R}Server close')
- soc.close()
- main=Thread (target=main)
- commands=Thread (target=commands)
- commands.start()
- main.start()
- except Exception as e:
- print(e)
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment