import socket as s
from threading import Thread

HOST = '0.0.0.0'
PORT = 4558

class ConnectionThread(Thread):
    def __init__(self,conn,addr):
        Thread.__init__(self)
        self.conn = conn
        self.addr = addr
        print("Thread {}:{} Started".format(addr[0],addr[1]))
    def run(self):
        self.conn.sendall("welcome to kalai's Server".encode())
        data = self.conn.recv(1024)
        while data:
            
            print("{}: ".format(self.addr[0]) + data.decode(), end="")
            data = self.conn.recv(1024)
            

sck = s.socket(s.AF_INET,s.SOCK_STREAM)
sck.setsockopt(s.SOL_SOCKET,s.SO_REUSEADDR,1)
sck.bind((HOST,PORT))
sck.listen()

while True:
    print("Waiting for a connection...")
    conn,addr = sck.accept()
    print("Connection recived from {}:{}".format(addr[0],addr[1]))
    
    ConnectionThread(conn,addr).start()
        
 