Hi!
I tried to implement a webserver that serves files from the filesystem. (html, css, js)
If the files are bigger then 10k, character are lost and the browser receives incomplete data.
For example i sended a file with 46.279 Bytes and the browser only receives 38.747 Bytes. I did a compare with "Beyond Compare" and it is not just the end of the file that is missing, there are holes.
I am using a NodeMCU board and the esp8266-20161017-v1.8.5.bin micropython image.
To verify my code, I tried other webserver and run into the same problem.
Does anyone have any idea why that happens?
This is the method that sends the file back to the browser:
def sendfile(socket, filename):
....print("Filename: {0}".format(filename))
....header = '''HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n'''
....socket.send(header)
....with open(filename, 'rb') as f:
........while True:
.............buffer = f.read(256)
.............if not buffer:
................break
.............print("Send buffer")
.............socket.send(buffer)
Webserver looses character
Re: Webserver looses character
Why not test the return value of send which is supposed to be the actual number of bytes sent ? Well I assume that's the case. The MicroPython docs don't say as much.
Re: Webserver looses character
Try socket.sendall(buffer)
Re: Webserver looses character
Yes, socket.sendall(buffer) solved the problem.
Ah, "socket.send()" stands for "send as much you want."
Thanks!
Ah, "socket.send()" stands for "send as much you want."
Thanks!
Re: Webserver looses character
That's what I use. I favor that. Should not loose a single byte...Roberthh wrote:Try socket.sendall(buffer)