1 from socket import * 2 #创建服务器端套接字对象 3 serverSocket = socket(AF_INET,SOCK_STREAM) 4 #绑定端口 5 serverSocket.bind(("",8899)) 6 #监听 7 serverSocket.listen(5) 8 #接收客户端的连接 9 clientSocket,clientInfo = serverSocket.accept() 10 #接收客户端发送的消息 11 recvData = clientSocket.recv(1024) 12 print("接收到%s的消息%s"%(str(clientInfo),recvData.decode(‘gb2312‘))) 13 #关闭连接 14 clientSocket.close() 15 serverSocket.close()
原文:https://www.cnblogs.com/monsterhy123/p/12701967.html