Skip to content

Instantly share code, notes, and snippets.

@sonicrules1234
Created February 27, 2010 16:26
Show Gist options
  • Save sonicrules1234/316804 to your computer and use it in GitHub Desktop.
Save sonicrules1234/316804 to your computer and use it in GitHub Desktop.
#Note that this is not an actual httpd, I just modified one of my existing scripts to work as an excho server
import socket
class sonichttpd :
def onConnect(self, sock, address) :
self.sock = sock
self.buffer = ""
self.address = address
self.status = {"connected":True}
self.startLoop()
def startLoop(self) :
while self.status["connected"] :
data = self.sock.recv(4096)
self.parseData(data)
self.sock.close()
def parseData(self, data) :
if True :
print "[IN %s] %s" % (self.address, data)
self.sock.send(data)
self.status["connected"] = False
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 9007))
s.listen(1)
while True :
conn, addr = s.accept()
httpd = sonichttpd()
httpd.onConnect(conn, addr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment