Created
April 25, 2013 02:27
-
-
Save joshkunz/5457074 to your computer and use it in GitHub Desktop.
Very simple line-based protocol
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
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