arduino-libraries / Ethernet

Ethernet Library for Arduino
http://arduino.cc/
259 stars 264 forks source link

v2.0.0 of lib functoning as web server - browser client gets cant connect #110

Open geetee24 opened 5 years ago

geetee24 commented 5 years ago

i have simple server app.
see: // https://wiznetmuseum.com/portfolio-items/lets-build-a-functional-arduino-webserver-with-the-ethernetsd-card-shield/?portfolioID=11350 // https://www.hackshed.co.uk/lets-build-a-functional-arduino-webserver-with-the-ethernet-sd-card-shield/

that app fails when a browser requests index.htlm that inside it contains.

<!DOCTYPE html>

argh

in chrome debugger you see it trying to open the 3 files at once and the bug is the 3rd file request immediately fails with err_connection_refused yet the 1st two download fine.

i think your library is not handling simultaneous connections?

Any help please.

JAndrassy commented 5 years ago

how are the request handled in sketch?

geetee24 commented 5 years ago

the library link i gave you is a super simple example that if you run it, you will see the exact error in the core library. use any browser and see it. I also see other google posts of the same problem with the library. Thanks. Note that I wrote my own much more feature rich web server and when I ported it to use your library, the same core issue surfaced.

geetee24 commented 5 years ago

see similar post here. https://arduino.stackexchange.com/questions/34743/ethernet-shield-multiple-simultaneous-connections-cause-tcp-reset

JAndrassy commented 5 years ago

sorry, but I don't see any code on that page in FF, Chrome or IE. There is "The following code should be altered to suit your setup:", but no code.

That Arduino SE Question is old. Which version of the library do you use?

geetee24 commented 5 years ago

i use your latest version.

see code webserverWithSdCard.zip

geetee24 commented 5 years ago

thank you.

JAndrassy commented 5 years ago

OK I found the code on the Wiznet page. It is inefficient, so slow and the browser times-out on the 3 request.

geetee24 commented 5 years ago

note that if i use same zip but swap out your library for the uiparduino and use their ethernet card, all is well.

JAndrassy commented 5 years ago

:-) I don't maintain this library (but I am a maintainer of the UIPEthernet library)

geetee24 commented 5 years ago

rats. i need this library fixed.

note that I use the uipethernet v1.0.4 and it too has a separate problem in that it cant handle large incoming webdav puts without tcp resetting. any advice?

geetee24 commented 5 years ago

oops i mean i use https://github.com/ntruchsess/arduino_uip

can your library handle large incoming data?

JAndrassy commented 5 years ago

do you know this library https://github.com/UIPEthernet/UIPEthernet ?

geetee24 commented 5 years ago

i will try that for the uip chip. still need this library fixed :( does your library support the zip app that I attached?

geetee24 commented 5 years ago

i tried your uiipard lib and it works great. Thanks. now i need THIS etrhernet lib fixed else the arduino ethner 2 card is worthless.

JAndrassy commented 5 years ago

write a better Web server. use buffering and caching headers. here is the Web server in my project. It uses my StreamLib for buffering.

geetee24 commented 5 years ago

what hardware and what lib does it use?

geetee24 commented 5 years ago

where is streamlib documented?

JAndrassy commented 5 years ago

what hardware and what lib does it use?

almost any. Ethernet (with W5500), UIPEthernet, esp8266, WiFiLink were used months. WiFiNina, WiFiEspAT, Ethernet(with W5100) were tested

where is streamlib documented?

https://github.com/jandrassy/StreamLib/blob/master/README.md

geetee24 commented 5 years ago

i reviewed your server. where is NetServer defined? Code?

JAndrassy commented 5 years ago

i reviewed your server. where is NetServer defined? Code?

the entire folder is one IDE project. the main file is Regulator.ino

geetee24 commented 5 years ago

so where are you saying the issue I am having with ethernet lib is? in my web server? where in your regulator code do you address this issue and solve for it?

JAndrassy commented 5 years ago

so where are you saying the issue I am having with ethernet lib is? in my web server? where in your regulator code do you address this issue and solve for it?

in WebServer.ino. for static file serving

1) buffering of the outgoing bytes with BufferedPrint, which wraps client 2) setting Content-length of response here 3) setting caching header 'Expires' for browser here

geetee24 commented 5 years ago

but how does that relate to the browser requesting multiple connections and gettting tcp resets from the arduino

JAndrassy commented 5 years ago

I wrote it earlier. The browser has a timeout until it expects a response. If you not handle the requests fast enough, some of the requests timeout. With cached files the requests for static files are not repeated next time.

you get tcp resets at first set of requests after reset of Arduino?

geetee24 commented 5 years ago

Yes

On Fri, Aug 23, 2019 at 12:03 PM Juraj Andrássy notifications@github.com wrote:

I wrote it earlier. The browser has a timeout until it expects a response. If you not handle the requests fast enough, some of the requests timeout. With cached files the requests for static files are not repeated next time.

you get tcp resets at first set of requests after reset of Arduino?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/arduino-libraries/Ethernet/issues/110?email_source=notifications&email_token=ABS6UTZO4I4IVRCUAC6VR3LQGAYAPA5CNFSM4IO2IHL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5BCEYA#issuecomment-524427872, or mute the thread https://github.com/notifications/unsubscribe-auth/ABS6UTYSOXQB6WBDQVWLTRTQGAYAPANCNFSM4IO2IHLQ .

-- Sent from Gmail Mobile

geetee24 commented 5 years ago

to see the issue in the ethernet library, do not enable browser caching - for that only masks the core issue - the bug in the library.

SapientHetero commented 5 years ago

This library has no more than one socket listening at a time. When a connection is made, there will be NO sockets listening while the library commands the W5500 to begin listening on a new socket. Current browsers establish up to 6 simultaneous connections to a server, and if this happens faster than your code can respond, some connection attempts will time out.

I modified this library to manage sockets in a manner more useful for servers and uploaded the new version to https://github.com/SapientHetero/Ethernet. You can tell it how many sockets you want listening at any time. It tracks the "last time used" for each socket, and closes the "oldest" sockets when needed to ensure the specified number of listeners are available.

I also fixed a number of bugs I found in this library that improve reliability.