First of all ,I'm a beginner in python. I developed a simple TCP echo server that works nice but I decided to take it a step further and make it a multi-threading one. The code compiles but when I start connecting clients, it stops working. The problem seem to be in the calling of the parent constructor, but I can't figure it out. Here's the code I've developed so far...
#!/usr/bin/env python
import socket, threading
class workingthread(threading.Thread):
def __init__(self,client,ip,port):
threading.Thread.__init___(self)
self.client=client
self.ip=ip
self.port=port
def run(self):
data=client.recv(6000)
print "Client Sent: ",data
client.send(data)
tcpsocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
tcpsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcpsocket.bind(("0.0.0.0",8000))
tcpsocket.listen(5)
(client,(ip,port))=tcpsocket.accept()
newthread= workingthread(client,ip,port)
newthread.start()
Thanks in advance :)
您的Thread.__init___(self)
有一个_
过多Thread.__init___(self)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.