Note that there are some explanatory texts on larger screens.

plurals
  1. POReading socket buffer using asyncore
    primarykey
    data
    text
    <p>I'm new to Python (I have been programming in Java for multiple years now though), and I am working on a simple socket-based networking application (just for fun). The idea is that my code connects to a remote TCP end-point and then listens for any data being pushed from the server to the client, and perform some parsing on this.</p> <p>The data being pushed from server -> client is UTF-8 encoded text, and each line is delimited by <code>CRLF</code> (<code>\x0D\x0A</code>). You probably guessed: the idea is that the client connects to the server (until cancelled by the user), and then reads and parses the lines as they come in.</p> <p>I've managed to get this to work, however, I'm not sure that I'm doing this quite the right way. So hence my actual questions (code to follow):</p> <ol> <li>Is this the right way to do it in Python (ie. is it really this simple)?</li> <li>Any tips/tricks/useful resources (apart from the reference documentation) regarding buffers/<code>asyncore</code>?</li> </ol> <p>Currently, the data is being read and buffered as follows:</p> <pre><code>def handle_read(self): self.ibuffer = b"" while True: self.ibuffer += self.recv(self.buffer_size) if ByteUtils.ends_with_crlf(self.ibuffer): self.logger.debug("Got full line including CRLF") break else: self.logger.debug("Buffer not full yet (%s)", self.ibuffer) self.logger.debug("Filled up the buffer with line") print(str(self.ibuffer, encoding="UTF-8")) </code></pre> <p>The <code>ByteUtils.ends_with_crlf</code> function simply checks the last two bytes of the buffer for <code>\x0D\x0A</code>. The first question is the main one (answer is based on this), but any other ideas/tips are appreciated. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload