HTTP server works with Chrome on PC, TCP resets on Android (2560, W5100)

Hi!

So, I've written an HTTP server for my Arduino and it works like a charm with every type of client software from PC/Chrome, FF, IE, Android/FF, to a goddamn smart TV, but for the love of God, it won't work with Chrome/Android.

I've made so that the client side of this project (written in JavaScript) sends only one HTTP request at a time to make sure the Ethernet Shield doesn't refuse the multiple connections.

After an Arduino reset, the first load from Android/Chrome is OK, the second one is sometimes OK, but after that it won't load again until an Arduino reset. In the meantime every other device/browser combination works well, even after dozens of page loads and hours of use.
The connections are most likely closed properly (the EthernetClient's disconnect function is called) after the response has been sent by the server, but I am still not sure if the problem is not with running out of sockets on the W5100. How do I check that?

I attached images of Chrome's networking debugger (or whatisitcalled), that shows how exactly the load fails and how it should look like, the delays between the requests are intentional.
I will probably attach Wireshark data too, but as making the Arduino connect to my home network via my laptop makes the latter go BSoD (because of the network interface bridging, thank you Windows 10), I might have to hack together a solution with OpenWRT and port mirroring on a SOHO router and that might take time, energy and most importantly, effort.
It is worth noted that at TCP level, the delays are caused by TCP reset from the Arduino, that much I could find out before my blood pressure became to high to continue with the systematic BSoDs.

Images: The goddamn Android/Chrome project - Album on Imgur

Hardware:
Server: Arduino Mega 2560 with an Ethernet Shield (W5100)
Client: As mentioned above

Software:
Server:
Arduino Ethernet library and Wiznet Ethernet library both tested, same results
ejeklint's websocket implementation (might be this?)

I will share a code snippet at some point, but it takes some time to strip down my server/client code (as it is long as frick) to a readable length that is still working, and I'm hoping that the problem is not with that.

As always, any help/remark/guess is appreciated!
Thank you for reading this far!

G.

but for the love of God, it won't do what it has to do on Chrome/Android.

The HTTP server isn't running on Chrome/Android. So, I don't understand this statement.

and I'm hoping that the problem is not with that.

That should be simple to test. Create a bare-bones server that replies the same to every request, simply echoing what the request was, in the tags.

SurferTim has some code on the Playground to test the socket status.

PaulS:
The HTTP server isn't running on Chrome/Android. So, I don't understand this statement.
That should be simple to test. Create a bare-bones server that replies the same to every request, simply echoing what the request was, in the tags.

SurferTim has some code on the Playground to test the socket status.

I've rewritten the first lines, now it makes sense.
I'll check SurferTim's code and write some test code as soon as I'll have some time!

Thank you for your reply!

G.

The main thing with servers is sending the response with multiple bytes per packet. If you send one byte per packet, phones will have a problem. Note my sample code in the playground sends 64 bytes per packet.
http://playground.arduino.cc/Code/WebServerST

SurferTim:
The main thing with servers is sending the response with multiple bytes per packet. If you send one byte per packet, phones will have a problem. Note my sample code in the playground sends 64 bytes per packet.
Arduino Playground - HomePage

My server buffers the data, so this might not be the issue, nevertheless I'll check your code too!

G.

czvendel:
My server buffers the data, so this might not be the issue, nevertheless I'll check your code too!

G.

What exactly does that mean? Does your code send more than one byte per packet?

Sorry for the long delay, I did not spend much time on the computer during the weekend.

SurferTim:
What exactly does that mean? Does your code send more than one byte per packet?

Yes, it does, I implemented that quite early as it was incredibly slow to send every byte in a separate packet. My server currently uses 64 byte buffer and Wireshark says it works like it should work. (64 byte payload sizes)
Although I'm kinda interested if there is a way to use the W5100's built-in buffers as rx/tx buffers.

I studied the issue at hand further, and it seems that the problem is around Android/Chrome's webpage refresh mechanism as it is running code/throwing errors that should not be ran/thrown. A nice location.refresh in the Javascript code seems to solve the problems.

I'll do some tinkering and update you!

G.

Since you are using an Arduino Mega2560 that has a decent amount of program space I would encourage you to look at two things that may help you with your project become a better project for the long term.

The first suggestion would be using a HTTP library called Webduino, which provides a nice API and abstracts away the core logic of HTTP itself, leaving you to focus more on decoding HTTP requests and supplying return data. No offense to Tim for his efforts.

The other thing I would suggest you look at is to use an Ethernet controller that far exceeds the clunkyness of the old W5100, and that is to use a W5500.

To tell a quick story; in the beginning, many light years ago, I started with what you have, basic code and a clunky W5100.
It worked reasonable at the time and for my then knowledge of Arduino micro-controllers.

But, quickly, I found short comings with reliability and any sort of performance for a small embedded controller with HTTP server.
So, I moved all my TCP communications to a small GNU/Linux board and then communicated back to Arduino via async serial using suitable data protocol.

Doing this provided me with great performance and also great reliability, since I wrote the code running the HTTP server from ground up for the GNU/Linux system.

In recent times I have wondered about the newer Wiznet controllers and read up on them.
I bought a handfull of small W5500 module online and made a test using the Webduino library and have been more than impressed with the results so far.

I made a simple loop to send out a block of 10k (ten thousand) characters via HTTP. I don't have the exact timing figures, but I do recall from what I saw, I right away thought, 'oh, yes, this is very good' Something in the order of 1MB per second I think was the figure.

I am now coding a new application, using DUE and W5500 to test a more elaborate and functional web server using HTTP and maybe web sockets.

I would encourage you to read up on the W5500 and how different it is to W5100 and then to also look at the Webduino library which I recall will be in the library section of this Arduino site.

Good luck :slight_smile:


Paul - VK7KPA