在根据https://linux.cn/article-6815-1.html作一个实践,加深一下相关概念的理解。
这下些的翻译也是极有意思的。
译者注:上面原作者所引用的那段话在国外的翻译是:I hear and I forget, I see and I remember, I do and I understand。外国人普遍认为出自孔子,但在查找这句英文的出处时,查到有篇博文称这句话的中文实际出自荀子的《儒效篇》,经查确实如此。
import socket HOST, PORT = '', 8888 listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listen_socket.bind((HOST, PORT)) listen_socket.listen(1) print 'Serving HTTP on port %s ...' % PORT while True: client_connection, client_address = listen_socket.accept() request = client_connection.recv(1024) print request http_response = """\ HTTP/1.1 200 OK Hello, World! """ client_connection.sendall(http_response) client_connection.close()