import socket
def handle_request(client):
buf = client.recv(1024)
client.send("HTTP/1.1 200 OK\r\n\r\n")
client.send("Hello, World")
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 8080))
sock.listen(5)
while True:
connection, address = sock.accept()
buf = connection.recv(1024)
print buf
#handle_request(connection)
#connection.close()
connection.send('HTTP/1.1 200 OK\r\n\r\n')
connection.send('Hello,World')
connection.close()
if __name__ == '__main__':
main()
转载于:https://www.cnblogs.com/eguotangsneg/p/6591180.html