Skip to content

Instantly share code, notes, and snippets.

@oxtoacart
Created January 31, 2014 22:36
Show Gist options
  • Save oxtoacart/8744669 to your computer and use it in GitHub Desktop.
Save oxtoacart/8744669 to your computer and use it in GitHub Desktop.
# FTE-Powered echo client program
import socket
import fte
import random
import string
def random_string(size):
"""Return a random alphanumeric string of length ``size``."""
chars = string.ascii_uppercase + string.digits
return ''.join(random.choice(chars) for x in range(size))
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 = '127.0.0.1' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = fte.wrap_socket(s,
outgoing_regex=client_server_regex,
outgoing_fixed_slice=256,
incoming_regex=server_client_regex,
incoming_fixed_slice=256)
s.connect((HOST, PORT))
# Altering the size of the random string has a big impact on throughput
chars = random_string(500000)
for i in range(1, 5000000):
s.sendall(chars)
s.close()
print 'Received', repr(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment