I have a webserver application that serves 1x HTML file with 5x reference CSS/JS files. Using a Wiznet W5500-based ethernet shield, only the initial HTML file & first external file (wrt the HTML code) load OK, subsequent loads return an "ERR_CONNECTION_REFUSED" message at the Client browser.
Oddly enough, when using an ENC28J60-based shield my webserver code runs! It serves up (slowly!) 5x external files & the 1x HTML file to the client without issue.
Hello. I had some issues with cheap china W5500 boards, where the W5500 share the same SPI bus as the SD card reader. So guess what happens when the SPI bus is busy, reading a file from the SD card?
I got this working and for future users posting the general approach I used.
The W5500 has 8x sockets. My mistake was to start only one EthernetServer (thus only opening up one port and the other 7x remain closed). When the client received the initial HTML it fired off several requests which were denied by the W5500 because only 1x port was opened..
My approach was to open 8x EthernetServers against each port, and cycle through them one-by-one, check if anything was .available() and then process. This way there are 8x sockets open for the client, so when it replies with several requests for the website resources they are are buffered against each open port and not denied outright (ERR_CONN_REFUSED).
It won't win any awards for speed (or elegance), but at least things are working.
No it doesn't. Using 1x EthernetServer opens 1x port, I needed several open (and thus several EthernetServers) so all client requests were received and buffered for the webpage to load correctly.
what happens if another client request is received while the 1x socket that is in use is not listening?
it waits until it is accepted. if it is already accepted then the packet will be there to be read. if another packet arrives it will be rejected and not acked so the client will re-transmit it after a short timeout. that is TCP.
That is correct. And what happens if the client receives another rejection on the second request? It gives up entirely, unless you are tweaking custom browser settings (max attempts > 50, max sockets < 1 etc) just to get it to work.
This is the issue I was having and why I needed multiple sockets listening to receive and buffer the web client requests.
BTW - I love your ENCLibrary! That is awesome and is what originally gave me hope on getting the project to work on the wiznet chip.
do you set the expiration header so the browser caches the static files?
I only maintain the EthernetENC library. the core of it is the 20 years old uIP library and the Arduino wrapper was written by Norbert Truchsess and I fixed many many bugs in his code to make the library usable.