python web的祖宗


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()
posted @ 2017-03-20 19:35  eguotangseng  阅读(141)  评论(0编辑  收藏  举报