w5500 webserver with limited sockets
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Share projects and connect with makers.
Joined before the site update? first.
New to WIZnet Makers?
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.
Know your password?
Need an account?
RE: w5500 webserver with limited sockets
by acpie360 ·
I only have three sockets reserved for an embedded web server. It has no problem with Chrome. However, I do use the non-blocking mode (SF_IO_NONBLOCK) for all three sockets.
RE: RE: w5500 webserver with limited sockets
by benjamin3er ·
Thank You for the quick answer!
How many resources (I mean images, css files, stuff that has to be loaded after the page is interpreted by the browser) do you have on your webserver? For me, the page itself can be handled with a single socket. However the 12 images that are requested after the page is received are not handled sequentially. Chrome (also checked with IE and Firefox) just fires back in parallel fashion and if I do not provide enough sockets, some of the images are not loaded.
So lets say I provide 4 sockets then
BTW. I also use SF_IO_NONBLOCK, which is the default after initialization of the chip
RE: w5500 webserver with limited sockets
by Mxyxixptlick ·
Most browsers will open up to 6 concurrent connections and will not retry if a connection is rejected (e.g., because you don’t have one listening when it tries to connect).
I revised an existing W5500 library to actively manage sockets while reserving some for other purposes. You’re welcome to use it, or to scavenge it for ideas or code snippets that serve your needs.
Look in particular at sockets.cpp, in which I’ve implemented a function named manageSockets() that closes connections as needed to maintain the number of listeners you specify and leave a socket untouched if allocated to other purposes. Note that it depends on other functions recording the last time of use for each socket.
You can find my version of the library at https://github.com/SapientHetero/Ethernet
RE: RE: w5500 webserver with limited sockets
by benjamin3er ·
Thank You,
I read your code and in fact it tackles the problem that I have.
I understand, that the mangeSockets() functions disconnects resp. closes the sockets as soon as possible, which is very reasonable. Closing of the idle conenctions is a very good thing. I like that you track the age of the connections…
But altogether, you still have to provide at least 6 sockets for a webserver (In order to guarantee that pages with many (>6) resources are loaded completely) ? Right ?
There is no way to run a webserver with 2 sockets ?
Otherwise I’ll instantly integrate your lib
RE: w5500 webserver with limited sockets
by Mxyxixptlick ·
I’ve found no way to run a webserver with less than 6 sockets using the current versions of Chrome, FireFox, Brave, Opera or Microsoft Edge browsers other than limiting the number of resources used by the pages you load. Browsers open multiple sockets to improve their own performance by loading resources in parallel at the expense of imposing a greater load on servers that they view as “not my problem”. There’s no way to limit the number of concurrent sockets used or to force retries of refused connections. This is what led me to write my socket management function.
You could change your pages to reduce the opportunity for browsers to demand concurrent sockets. Embed javascripts and css in your header, and Base64-encode any jpg images and embed them in your HTML. You could also host resources that don’t strictly need to be on your system (e.g., .css & script files) on another server. If you eliminate all “linked” resources in your pages, the browser would need only one socket to load them.
Another option is to specify long cache periods using the Cache-Control pragma for linked resources in your pages if they don’t change often. You’ll still get refused connections the first few times you load your pages, as the browser must load every resource once in order to cache it. But once all are cached you’ll be fine until the specified cache period expires. The downside is that if these resources change before the cache period expires, users will have to be trained to force a reload using the relevant browser feature.
You haven’t said what your “other services” are, but clever socket sharing may allow you to do what you need despite browsers hogging 6 while loading pages. Is it possible to spread these services out in time, perhaps queuing them to run as sockets become available, or must they run on a strict schedule?
If you use my code you’ll notice that I’ve included calls to a wdtClear() function in certain loops. This function resets a watchdog timer on the ATSAMD5x family of controllers. I’ve posted my watchdog timer code at https://github.com/SapientHetero/Watchdog-Timer-for-ATSAMD51J19A if you want to use it. If not, you’ll need to comment out the wdtClear() calls or add conditional compilation directives to turn them off.
RE: w5500 webserver with limited sockets
by benjamin3er ·
That’s how it feels, it would have been really nice though. Maybe the w5500 itself could have some “pseudo” sockets that have window size 0 and force the browser to retry until it gets a “real” socket. But this is a completely different story. I might start a new discussion on that…
That looks like a hack that could work.
I have only basic knowledge about web programming, so I was looking into http2 and pipelining (HTTP pipelining - Wikipedia), which looked very promising but did not work since most browser do not support pipelining
I have a TCP communication to poll status data from the uC. I know this takes only one socket (using a different port), but it is an unpleasant feeling to not have the control over the webserver sockets. I’m not deep into web stuff, but was just thinking what if the next update of chrome allows 8 or 10 parallel socket requests…
I know your proposed solution with java script and embedding the resources will still work, but it leaves me with the feeling that it does not scale well.
Thank You very much for the detailed responses!
RE: w5500 webserver with limited sockets
by Mxyxixptlick ·
“what if the next update of chrome allows 8 or 10 parallel socket requests…”
Actually, they used to use more sockets just a few years ago. Not sure why they dialed it back, perhaps in recognition of the coming IoT?
Still, I feel your pain. It would be nice to have a device as inexpensive as the W5500 that supported more sockets.