Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By beic
#76534 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
User avatar
By QuickFix
#76540 You can only pass (a pointer to) a method as parameter, not a method with parameter as parameter.
User avatar
By btidey
#76544 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.