initial import of Connelly's public domain I2P python lib

This commit is contained in:
jrandom
2004-07-21 07:42:29 +00:00
committed by zzz
parent 8603250d73
commit 5214436d18
39 changed files with 4533 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
# -----------------------------------------------
# stream_server.py: Simple stream server
# -----------------------------------------------
import i2p
from i2p import sam
S = sam.socket('Dave', sam.SOCK_STREAM)
S.listen(10) # Queue up to 10 connections
print 'Serving at:', S.dest
while True:
try:
(C, remotedest) = S.accept() # Get a connection
f = C.makefile() # File object
req = f.readline() # Read HTTP request
s = '<h1>Hello!</h1>' # String to send back
f.write('HTTP/1.0 200 OK\r\nContent-Type: text/html' +
'\r\nContent-Length: ' + str(int(len(s))) + '\r\n\r\n' + s)
f.close() # Close file
C.close() # Close connection
except sam.Error, e:
# Recover from SAM errors
print 'Warning:', str(e)