Created
January 31, 2014 21:12
-
-
Save oxtoacart/8743252 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
# FTE-Powered echo server program | |
import socket | |
import fte | |
client_server_regex = '^GET\\ \\/([a-zA-Z0-9\\.\\/]*) HTTP/1\\.1\\r\\n\\r\\n$' | |
server_client_regex = '^HTTP/1\\.1\\ 200 OK\\r\\nContent-Type:\\ ([a-zA-Z0-9]+)\\r\\n\\r\\n\\C*$' | |
HOST = '' # Symbolic name meaning all available interfaces | |
PORT = 50008 # Arbitrary non-privileged port | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s = fte.wrap_socket(s, | |
outgoing_regex=server_client_regex, | |
outgoing_fixed_slice=256, | |
incoming_regex=client_server_regex, | |
incoming_fixed_slice=256) | |
s.bind((HOST, PORT)) | |
s.listen(1) | |
conn, addr = s.accept() | |
print 'Connected by', addr | |
while 1: | |
data = conn.recv(1024) | |
if not data: break | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment