python - Multi threaded server send function -
i got multi threaded server code , works when type send client not sending send function work if send data string knows what's problem?
#!/usr/bin/env python import socket, threading class clientthread(threading.thread): def __init__(self, ip, port, clientsocket): threading.thread.__init__(self) self.ip = ip self.port = port self.csocket = clientsocket print "[+] new thread started "+ip+":"+str(port) def run(self): print "connection : "+ip+":"+str(port) clientsock.send("welcome server ") data = "dummydata" while len(data): data = self.csocket.recv(2048) print "client(%s:%s) sent : %s"%(self.ip, str(self.port), data) userinput = raw_input(">") self.csocket.send(userinput) print "client @ "+self.ip+" disconnected..." host = "0.0.0.0" port = 4444 tcpsock = socket.socket(socket.af_inet, socket.sock_stream) tcpsock.setsockopt(socket.sol_socket, socket.so_reuseaddr, 1) tcpsock.bind((host, port)) while true: tcpsock.listen(4) print "nlistening incoming connections..." (clientsock, (ip, port)) = tcpsock.accept() #pass clientsock clientthread thread object being created newthread = clientthread(ip, port, clientsock) newthread.start()
well, can see @ least 1 thing prevent working intended:
def run(self): print "connection : "+ip+":"+str(port) clientsock.send("welcome server ")
clientsock
undefined.
Comments
Post a Comment