Last active
November 17, 2020 04:30
-
-
Save pervognsen/e28b9a5af85782e9a7976b6996a76303 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
buffer = b'' # This is the partial line buffer. | |
while 1: | |
buffer += socket.recv(1024) # Read up to 1024 bytes and append it to the buffer. | |
lines = buffer.split(b'\n') # Split the buffer by newlines. | |
buffer = lines[-1] # The last piece is a partial line. | |
for line in lines[:-1]: # Every other piece is a complete line. | |
process(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment