Skip to content

Instantly share code, notes, and snippets.

@chao-he
Created November 22, 2013 11:43
Show Gist options
  • Save chao-he/7598626 to your computer and use it in GitHub Desktop.
Save chao-he/7598626 to your computer and use it in GitHub Desktop.
a dummy http server
import socket
import logging
HOST = '' # Symbolic name meaning the local host
PORT = 9000 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
msg = ""
with open("msg.txt") as f:
msg = f.read()
f.close()
print "listen on %s:%s" % (HOST, PORT)
while True:
conn, addr = s.accept()
print "%s:%s" % addr, 'connected'
try:
data = conn.recv(1024)
if not data:
break
print "recv ============================"
print data
print "send ============================"
conn.send(msg)
except Exception,e:
logging.exception(e)
break
finally:
conn.close()
print "close"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment