-->
Page 1 of 3

Pass data to server.on

PostPosted: Wed Jun 20, 2018 2:53 pm
by beic
Hi there,

I'm trying to make a multi port web server, but I have a little trouble with it.

Here is my issue:

I don't know how to pass data to the:

Code: Select allserver.on("/", handleRoot);


I would like to do like this:

Code: Select allserver.on("/", handleRoot(false));
serverExt.on("/", handleRoot(true));

void handleRoot(boolean blIsExtAccess)
 {

String stData = "Hello there";

if (blIsExtAccess == false)
  {
    server.send(200, "text/html", stData);
  } else {
    serverExt.send(200, "text/html", stData);
  }
}


But for some reason I'm getting compile error: "invalid use of void expression"

Can some help me with it?

Kind regards,
Viktor

Re: Pass data to server.on

PostPosted: Thu Jun 21, 2018 2:19 am
by QuickFix
You can only pass (a pointer to) a method as parameter, not a method with parameter as parameter.

Re: Pass data to server.on

PostPosted: Thu Jun 21, 2018 4:38 am
by beic
@QuickFix

Can you please give me some simple example for my issue?

Thank you!

Re: Pass data to server.on

PostPosted: Thu Jun 21, 2018 4:44 am
by btidey
If you want two different on calls to do different things then you need to define them as two different methods, e.g. handleRoot and handleRootExt.

If they behave similarly such that you want to make much of the code common then define the common code as say handleRootBase with a parameter to modify its behaviour. Then call handleRootBase from handleRoot and handleRootExt with that parameter.