ETHERNET library : problem with "Client = server.available" within a void()

Hi,

I'm actually coding a HTTP SERVER with these features :

  • Identification of each field inside a CLIENT HTTP REQUEST (GET/POST ; User-Agent ; Accept-Language ; etc ...)
  • Supports GET and POST requests with parsing of values passed by a FORM (only on ENCTYPE : "application/x-www-form-urlencoded" // "multipart/form-data" NON SUPPORTED)
  • Basic AUTHENTICATION supported (ability to select on which directory : "/" or "/public")
  • Supports HTTP STATUS CODES (200 ; 301 ; 400 ; 401 ; 404 ; can do more !)
  • Serves files directly from SD/microSD card
  • Identifies files existence (if not exist : HTTP ERROR CODE 404 is sent)
  • Identifies files extensions and send MIME Types (Example : "Content-Type: image/gif")
  • Gather the length of requested file to serve and send it (Example : "Content-Length: 853")
  • Supports MIME types when answer to clients (HTTP FIELD "Content-Type")
  • Can update values running in RAM (byte, integer, float, string) thru a FORM send
  • Supports timeout on requests (avoiding Arduino's to stop code execution if bytes from client takes too long to come)

Ok ... so well, it runs really fine as for now, it consumes only a little more than 2 kB of RAM !
But, i have a big problem with ETHERNET library where i can't pass the "Client xxxx = server.available();" to a void called inside the one i initialize the Client.

I certainly lacks some knowledge on passing variables from one void to another, but usualy i don't have problems to do it !
Here i have !

I tried to initialize the client object sooner than inside the loop() (not in the setup(), well before like ip/mac/subnet/ etc ...) and i still have the problem happening.

The reason why i'm looking at a solution for this is that when a client is loading a page, if another request is made from the same client, the data going from the arduino to the client (1st request), appear on the 2nd request (even the HTTP code !!!).
It basically means that even if the W5100 module is able to supports 4 simultaneous connections, it is problematic to isolate them !

Do someone encountered the same problem ?

Thanks !

The w5100 will support 4 connections, but not really simultaneously. It services one connection at a time. The rest must wait until it is their turn. Big downloads and slow connections can lead to timeouts on the client end.

I am not certain what you mean by "within a void()". This is a short snippet of code that should do what I think you want.

void loop()
{
   Client client = server.available();
   if(client)
   {
      checkClient(client);
   }
}

void checkClient(Client thisClient)
{
   // do something with thisClient
}

But, i have a big problem with ETHERNET library where i can't pass the "Client xxxx = server.available();" to a void called inside the one i initialize the Client.

Sure you can. You have our permission.

If you understood what you were doing, it would really help.

First, it sounds like you want to pass the Client instance, xxxx, to something, not some silly string. You can do either one, but you need to define which it is you want to do.

Second, that something is a function, not a void. Void is a return type, like int. If the function returned an int, you would not say "to a int called inside the one i initialize the Client", would you. Clearly that sounds dumb. So does misusing void.

The reason why i'm looking at a solution for this is that when a client is loading a page, if another request is made from the same client, the data going from the arduino to the client (1st request), appear on the 2nd request (even the HTTP code !!!).

If another request is made, while one is being processed, there is no easy way to know whether the machine that submitted the second request is the same as the one that submitted the first request. Even if there were, there is no way of knowing whether the same process on that machine issued the two requests, or whether the requests were issued by two different processes.

So, you must treat every request as completely independent.

You can pass a reference to a Client instance to a process, which sounds like what you need to do.

Oups !!!

You were right sorry for that ! please forgive me ... :fearful: :blush:

I had to pass the Client directly as argument of my function for it to work !

Now i can laod pages that loads multiple content located on the arduino.
When the first request is being worked, the second (and the others) waits for the first one to end.

Thanks !

Now i have an arduino http server fully working :slight_smile: !!! yeeeeeha !