我想線程服務器插座蟒。我從互聯網上找到了這個代碼。我工作很好,但我不知道發生了什麼。 任何人都可以簡單介紹一下它,我想從主數據發送到MiTcpHandler類。我怎樣才能做到這一點?線程服務器套接字在python
import SocketServer
import threading
import time
class MiTcpHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = ""
while data != 'End':
data = self.request.recv(1024)
print data
time.sleep(0.1)
class ThreadServer(SocketServer.ThreadingMixIn,SocketServer.ForkingTCPServer):
pass
def Main():
host=''
port = 9998
server = ThreadServer((host,port),MiTcpHandler)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.start()
Main()
我建議你閱讀'SocketServer'模塊的文檔:https://docs.python.org/2/library/socketserver.html – mhawke