py---------socketserver
同时两个客户端连接,
server 不能有input
server端根据client端的要求去执行固定的代码
server.py
#-*- coding:utf-8 -*- import time import socketserver class Myserver(socketserver.BaseRequestHandler): #必须学继承 def handle(self): #必须叫handle conn = self.request # print(conn) time.sleep(3) conn.send(b'hello') time.sleep(4) conn.send(b'hello2') myserver = socketserver.ThreadingTCPServer(('127.0.0.1',9000),Myserver) #把类名传过来 myserver.serve_forever() #启动socket_server 端
client1.py
#-*- coding:utf-8 -*- import socket sk = socket.socket() sk.connect(('127.0.0.1',9000)) print(sk.recv(1024)) print(sk.recv(1024)) sk.close()
client2.py
import socket sk = socket.socket() sk.connect(('127.0.0.1',9000)) print(sk.recv(1024)) print(sk.recv(1024)) sk.close()
本文来自博客园,作者:王竹笙,转载请注明原文链接:https://www.cnblogs.com/edeny/p/9178689.html