Skip to content

Instantly share code, notes, and snippets.

@joshkunz
Created April 25, 2013 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshkunz/5457074 to your computer and use it in GitHub Desktop.
Save joshkunz/5457074 to your computer and use it in GitHub Desktop.
Very simple line-based protocol
LINE_SPLITTER = "\r\n\r\n"
def handle_client((csock, address)):
buffer = ""
while True:
tmp_buffer = csock.recv(RECV_SIZE)
if tmp_buffer == "": break
buffer += tmp_buffer
line = buffer.split(LINE_SPLITTER, 1)
if len(line) < 2: continue
else:
handle_message(csock, line[0])
buffer = line[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment