标签:
一、socket 编写server的步骤:
1 socket = socket.socket( family, type )
1 socket.bind( address )
socket.listen( backlog )
1 connection, address = socket.accept()
1 #coding=utf-8 2 import socket 3 BUF_SIZE = 1024 4 host = ‘localhost‘ 5 port = 8082 6 7 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 8 server.bind((host, port)) 9 server.listen(10) #并发数 10 while True: 11 client, address = server.accept() 12 data = client.recv(BUF_SIZE) 13 client.send(data) 14 print(data.decode()) #python3 要使用decode 15 client.close()
三、客户端请求:
标签:
原文地址:http://www.cnblogs.com/xilouch/p/4578528.html