Created
February 27, 2010 16:26
-
-
Save sonicrules1234/316804 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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