简体   繁体   English

Python中的多线程TCP Echo服务器

[英]Multi-Threading TCP Echo Server In Python

First of all ,I'm a beginner in python. 首先,我是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. 我开发了一个简单的TCP回显服务器,效果很好,但我决定将其进一步发展,使其成为多线程服务器。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM