Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python程序中的两个客户端同时从两个tcp服务器接收数据_Python_Networking_Tcpclient - Fatal编程技术网

python程序中的两个客户端同时从两个tcp服务器接收数据

python程序中的两个客户端同时从两个tcp服务器接收数据,python,networking,tcpclient,Python,Networking,Tcpclient,我正在尝试编写一个python程序,它将创建两个tcp客户端。 然后我将让这两个客户端从两个服务器接收数据。(S1-->C1,S2-->C2)。 我已经使用多线程库实现了服务器端 from threading import Thread from socketserver import ThreadingMixIn from http.server import HTTPServer, BaseHTTPRequestHandler class Handler(BaseHTTPRequestH

我正在尝试编写一个python程序,它将创建两个tcp客户端。 然后我将让这两个客户端从两个服务器接收数据。(S1-->C1,S2-->C2)。 我已经使用多线程库实现了服务器端

from threading import Thread
from socketserver import ThreadingMixIn
from http.server import HTTPServer, BaseHTTPRequestHandler


class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.end_headers()
        while True:
            print(threading.current_thread())
            self.wfile.write(bytes("Hello World!", "utf-8"))
            time.sleep(1)


class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
    daemon_threads = True


def serve_on_port(port):
    server = ThreadingHTTPServer(("localhost", port), Handler)
    server.serve_forever()


if __name__ == "__main__":

    Thread(target=serve_on_port, args=[8080]).start()
    Thread(target=serve_on_port, args=[8081]).start()
我也在浏览器上检查过这个。这将在不同端口上每秒打印字符串“hello world”

现在客户端仍然有问题。 这里应该是异步IO还是多线程

先谢谢你