TCP Socket Closes due to Small buffer

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
AgentSmithers
Posts: 8
Joined: Fri Feb 17, 2017 6:23 pm

TCP Socket Closes due to Small buffer

Post by AgentSmithers » Wed Feb 22, 2017 4:22 am

Hi everyone,
I am not sure if this is a bug or if I am just not doing something correctly.
I am hosting a HTTP Webserver and I use Recv to get the first 128 bytes, the HTTP request itself is about 500+ bytes but I don't need it. I find that if I do not set my buffer to 768bytes to receive the full packet my connection closes prematurely.
Is there a SOCKOPT i can set to overcome this issue or is my only option to expand the buffer and report this as a bug?
Thank you!!!

AgentSmithers
Posts: 8
Joined: Fri Feb 17, 2017 6:23 pm

Re: TCP Socket Closes due to Small buffer

Post by AgentSmithers » Wed Feb 22, 2017 9:43 pm

Hi everyone,
I just wanted to check in and see if there was any more additional information I could provide to help troubleshoot this issue?

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: TCP Socket Closes due to Small buffer

Post by devnull » Thu Feb 23, 2017 4:20 am

Hi;

I know that I am not really answering your question, but I always use 1024 bytes in the receiving buffer:

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:
            self.request(conn,raw)

AgentSmithers
Posts: 8
Joined: Fri Feb 17, 2017 6:23 pm

Re: TCP Socket Closes due to Small buffer

Post by AgentSmithers » Thu Feb 23, 2017 6:38 pm

devnull wrote:Hi;

I know that I am not really answering your question, but I always use 1024 bytes in the receiving buffer:

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:
            self.request(conn,raw)
Thank you for the reply sir. The issue that I am having is that multiple requests are being generated by clients at the same time and its causing a large amount of time to elapse before it times out for the ESP to get to the next request, Now If I just check the first few bytes I can tell that the request is one that can be just discards or not however to make this work I just need to check the first few bytes, It seems that processing all 1024 of that just delays the whole process :-\

Post Reply