'Multi-threaded server socket using python

How can I use threading to receive and send data in any time in this server socket code?

I can't send and receive data in any time with this code to a client and I should wait for client message to receive then I would be able to send data to client.

import socket
from threading import *
class soc():
     def __init__(self,s,conn, addr):

          self.s=s
          self.conn=conn
          self. addr= addr
          self.s=socket.socket()
          self.s.bind(('localhost',1234))
          
     def listen(self ):
          self.s.listen()
          print ('listening...')
          self.conn,self. addr=self.s.accept()
          
          while True:
               data='server: '+input('server:')
               self.conn.send(data.encode())
               print('Client sent:', self.conn.recv(1024).decode())

          
soc=soc('s','conn','addr')

soc.listen( )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source