python 3 案例写法
web框架的本质 socket
import socketdef handle_request(client): ???buf = client.recv(1024) ???client.send("HTTP/1.1 200 OK\r\n\r\n".encode(‘utf-8‘)) ???client.send("<h1 style=‘color:red‘>Hello, World ?send ?This is and me python project</h1>".encode(‘utf-8‘))def main(): ???sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ???sock.bind((‘localhost‘,8000)) ???sock.listen(5) ???while True: ???????connection, address = sock.accept() ???????print(connection, address) ???????handle_request(connection) ???????connection.close()if __name__ == ‘__main__‘: ???main()
网站显示:
web框架根本Socket
原文地址:http://www.cnblogs.com/Mjonj/p/7676962.html