Webserver Issue - Wiznet W5500 & Multiple Files

Howdy,

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.

It looks like the exact issue found here: https://forum.arduino.cc/t/web-server-issues-serving-pages-with-multiple-reference-files/651042, but given the ENC28J60 can handle the application I'm keen to get the W5500 working as well. The W5500 is much more powerful, handles the TCP/IP stack & saves flash on the microcontroller.

Does anyone know how I can have the W5500 serve multiple files in a webserver application?

Thanks for your help!

I never hade issues with a HTML and linked javascript & css "files".
make a prototype and post it showing your problem.

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?

here I have an example of serving a html page and a JavaScript js on an Arduino

https://werner.rothschopf.net/microcontroller/202011_arduino_webserver_fetch_api_en.htm

Hi Everyone,

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.

the EthernetServer already does what you described as soluion

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.

It seems you mix up ports and sockets.
There is no need to create 8 server instances for one HTML and several CSS/JS files.

How can one buffer several different client requests on one socket then?

you get a client with server.available() or server.accept(), you read the request, send a response, stop() the client and repeat

While you are processing one client request, what happens if another client request is received while the 1x socket that is in use is not listening?

a single core MCU without a multithread OS will handle one request after another.

F1: can you post a short code which demonstrates the issues you have and shows what you want to get solved?

Because as already mentioned, a page with several included files is no problem for the W5500.

F2: What microcontroller are you using?

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.