Oct-29-2022, 12:10 PM
I simply call it data exchange server. It does not fit into definitions just mentioned above. The server simply accepts data from one client, manipulates it and sends the data to other clients and so on.
#!usr/bin/python import threading from threading import * import socket import sys def clientthread(conn): buffer="" while True: data = conn.recv(8192) buffer=data.decode('utf-8') print (buffer) print("data recieved") #conn.sendall(reply) conn.close() def main(): try: host = '10.102.3.16' port = 1000 tot_socket = 6 list_sock = [] for i in range(tot_socket): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) s.bind((host, (port*(i+1)))) s.listen(10) list_sock.append(s) print ("[*] Server listening on %s %d" %(host, (port*(i+1)))) while 1: for j in range(len(list_sock)): conn, addr = list_sock[j].accept() print ('[*] Connected with ' + addr[0] + ':' + str(addr[1])) threading.Thread(target=clientthread,args=(conn,)).start() print(threading.active_count()) s.close() except KeyboardInterrupt as msg: sys.exit(0) if __name__ == "__main__": main()
(Oct-30-2022, 04:33 PM)gary Wrote: [ -> ]Here is my code below that estabishes 6 sockets bearing port No. 1000 to 6000. I am able to recieve the data from client connected to port 1000. However for other clients, I am unable to recieve data in server.
def handleConnected(self): self.thread_stop = False print(self.address, 'connected') if self not in wss: wss.append(self) for i in wss: print("client was added") print(wss) # Start a thread per connection t2 = threading.Thread(target=self.temp_controll, args=(512, 'get')) # (address, value) #, daemon= True) t2.start()