http server closing connection

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

http server closing connection

Post by devnull » Sun Feb 26, 2017 1:35 pm

Seem that I am pretty much the only person posting on this forum ?!

I have a problem with my simple http server related to the size of the received request.

The following is a code snippet of the bit that handles the request.

Something strange is happening once the received packet hits 536 bytes, if I increase the sent data by just 1 byte, the browser errors with CONNECTION RESET.

But the stranger thing is, even increasing the transmitted by 1 or more bytes, the print() statement always shows 536 bytes, and even more strange is that the received data in the same print statement is not truncated and is 100% complete.

This is obviously something to do with the way I am reading the data.

I have spent several hours today tracking this down and would really appreciate some help ?!

Code: Select all

    while True:
      conn, addr = self.sock.accept()
      raw = conn.recv(1024).decode('UTF-8')
      if not raw:
        print('Null Request.',addr)
        self.close(conn)
      else:
        print(raw,len(raw))
        self.request(conn,raw)

Post Reply