python程序中的两个客户端同时从两个tcp服务器接收数据
我正在尝试编写一个python程序,它将创建两个tcp客户端。 然后我将让这两个客户端从两个服务器接收数据。(S1-->C1,S2-->C2)。 我已经使用多线程库实现了服务器端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
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还是多线程
先谢谢你