- import socket
- host=''
- port=51234
- s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
- s.bind((host,port))
- s.listen(1)
- y="""HTTP/1.0 200 OK
hello world
://www.baidu.com">baidu
- """
- while 1:
- clientsock,clientaddr = s.accept()
- #process the connection
- print ("Got connection from", clientsock.getpeername())
- data = clientsock.recv(4096)
- n=clientsock.send(y)
- clientsock.close()
现在打开浏览器,地址栏内输入 localhost:51234, 可以看到服务器的回应。
阅读(3370) | 评论(0) | 转发(0) |