receiving command through uno server

hi,

I am attempting to get a program that will take a call from an ip address such as "192.168.1.86:50/?ledOn!" to print out on to Serial or to run a function.
My desired outcome would be to the same effect as:

Serial.println("ledOn");
or
if (input == 'ledOn') {
ledON();
}
[code/]

Here is my full code: 
[code]

#include <SPI.h>
#include <Ethernet2.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x10-71, 0x8E }; //physical mac address
byte ip[] = { 192, 168, 1, 86}; // ip in lan
byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(50); //server port
//String readString; 

const byte maxNum = 100;
char charRead[maxNum]; 
char inNum = 0;
bool anyMore = false;
const byte numChars = maxNum;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
char endMark = '!';
char startMark = '?';
bool comingIn = false;

void setup(){
    Serial.begin(9600);
   // Serial.println("Serial Up");
  //pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  //Serial.println("ethernet begin done");
  pinMode(4, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(13,HIGH);
  digitalWrite(4, HIGH);
  //Serial.println("pins done");
  delay(2000);
  server.begin();
  Serial.println("server done");
  Serial.println(Ethernet.localIP());
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
 //Serial.print("server available");
  if (client) {
    //Serial.println("allOK");
    if (client.connected()) {
      if (client.available()) {
         char c = client.read();
        //read char by char HTTP request
        while (c != endMark && inNum < maxNum && comingIn == true) {
           char c = client.read();
           charRead[inNum] += c;
          //store characters to string 
          //Serial.print(c);
          inNum ++; 
           c = NULL;
Serial.println(charRead);
//delay(2);
  client.flush(); 
        }
        comingIn = false; 
       
        if (c == startMark){
          comingIn = true;
        }
 
        //if HTTP request has ended
        if (c == endMark || inNum >= maxNum) {

          ///////////////
          //Serial.println(charRead); //print to serial monitor for debuging 

          client.println("HTTP/1.1 200 OK"); //send new page
         
          
          client.println("Content-Type: text/html");
          client.println();


          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE> Box of tricks... </TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Arduino button's</H1>");
          
          client.println("<a href=\"/?on!\">ON</a>"); 
          client.println("<a href=\"/?off!\">OFF</a>"); 

          
client.println("<a href=\"/?red!\">RED</a>");
client.println("<a href=\"/?green!\">GREEN</a>");
client.println("<a href=\"/?blue!\">BLUE</a>");
client.println("<a href=\"/?cyan!\">CYAN</a>");
client.println("<a href=\"/?purple!\">PURPLE</a>");
client.println("<a href=\"/?yellow!\">YELLOW</a>");
client.println("<a href=\"/?curtainClose!\">CURTAINCLOSE</a>");
client.println("<a href=\"/?curtainOpen!\">CURTAINOPEN</a>");
client.println("<a href=\"/?brightness!\">BRIGHTNESS</a>");
client.println("<a href=\"/?l!\">LEDON</a>");
client.println("<a href=\"/?f!\">LEDOFF</a>");

          client.println("</BODY>");

          
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          /*if(readString.indexOf("on") == -1) {
          } else {
            Serial.println(readString.indexOf("on"));
            
            Serial.println("on");

          }
          if(readString.indexOf("off") != 1)//checks for off
          {
            Serial.println(readString.indexOf("off"));
          
            Serial.println("off");
            }
           if(readString.indexOf("red") != 1)//checks for off
          {
            Serial.println(readString.indexOf("red"));
          
            Serial.println("red");
            }
            if(readString.indexOf("green") != 1)//checks for off
          {
            Serial.println(readString.indexOf("green"));
          
            Serial.println("green");
            }
            if(readString.indexOf("blue") != 1)//checks for off
          {
            Serial.println(readString.indexOf("blue"));
          
            Serial.println("blue");
            }
            if(readString.indexOf("cyan") != 1)//checks for off
          {
            Serial.println(readString.indexOf("cyan"));
          
            Serial.println("cyan");
            }
            if(readString.indexOf("purple") != 1)//checks for off
          {
            Serial.println(readString.indexOf("purple"));
          
            Serial.println("purple");
            }
            if(readString.indexOf("yellow") != 1)//checks for off
          {
            Serial.println(readString.indexOf("yellow"));
          
            Serial.println("yellow");
            }
            if(readString.indexOf("curtainOpen") != 1)//checks for off
          {
            Serial.println(readString.indexOf("curtainOpen"));
          
            Serial.println("curtainOpen");
            }
            if(readString.indexOf("curtainClose") != 1)//checks for off
          {
            Serial.println(readString.indexOf("curtainClose"));
          
            Serial.println("curtainClose");
            }
            if(readString.indexOf("brightness") != 1)//checks for off
          {
            Serial.println(readString.indexOf("brightness"));
          
            Serial.println("brightness");
            }
          if(readString.indexOf("ledon") != -1) {
            Serial.println(readString.indexOf("ledon"));
          digitalWrite(13, HIGH);
          delay(2000);
            Serial.println("ledon");
            }
            if(readString.indexOf("ledoff") == -1){
            } else {
            Serial.println(readString.indexOf("ledoff"));
          digitalWrite(13, LOW);
            Serial.println("ledoff");
            }
            
            if (readString.indexOf("l") < -1) {
              digitalWrite(13,HIGH);
              Serial.println("ledon"); 
            } else  if (readString.indexOf("f") < -1) {
              digitalWrite(13,LOW); 
            } 
          //clearing string for next read
          readString="";
*/
Serial.println(charRead[maxNum]);
        if (charRead == "?l") {
          digitalWrite(13,HIGH); 
        } else if (charRead == "?f") { 
          digitalWrite(13,LOW);
        } else if (charRead == "?on") { 
          Serial.println("on");
        }
        inNum = 0; 
        charRead[maxNum] = NULL;
      }
    }
  }
}
inNum = 0; 
charRead[inNum] ="";
}

void input() {
  recvWithEndMarker();
 showNewData();
}


void recvWithEndMarker() {
 static byte ndx = 0;
 char endMarker = '\n';
 char rc;
 
 // if (Serial.available() > 0) {
           while (Serial.available() > 0 && newData == false) {
 rc = Serial.read();

 if (rc != endMarker) {
 receivedChars[ndx] = rc;
 ndx++;
 if (ndx >= numChars) {
 ndx = numChars - 1;
 }
 }
 else {
 receivedChars[ndx] = '\0'; // terminate the string
 ndx = 0;
 newData = true;
 }
 }
}

void showNewData() {
 if (newData == true) {
//Serial.print("This just in ... ");
 Serial.println(receivedChars);
 server.println(receivedChars);
 newData = false;
 }
}

after running this for the call above i keep receiving this in serial monitor:

@an! HTTP/1.1
Host: 192.168.1.86:50
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Accept: d

Any suggestions to help me make this code work properly or more efficient would be appreciated.
Thank you.

Start by fixing the tags it’s all mixed up

While you are fixing the aforementioned code tags there are a few other things you can do to make things easier for people trying to help you:

  • Remove code that isn't being used ie. input(), recvWithEndMarker(), showNewData().
  • Code that you have commented out for whatever reason can also be removed; in particular that huge block in the middle of your sketch. Remember that some people will be using mobile devices to read your question and it can be difficult to recognise commented out code.
  • Try to structure your code better; try to create functions where appropriate. One example you could do now would be the inline HTML that you have; you could stick it in a function like this:
void printIndexHtml(Stream& stream) {
  stream.print(F(
    "HTTP/1.1 200 OK\n"
    "Content-Type: text/html\n\n"
    
    "<HTML>\n"
    "<HEAD>\n"
    "<TITLE> Box of tricks... </TITLE>\n"
    "</HEAD>\n"
    "<BODY>\n"
    
    "<H1>Arduino button's</H1>\n"
    
    "<a href=\"/?on!\">ON</a>\n"
    "<a href=\"/?off!\">OFF</a>\n"
    
    "<a href=\"/?red!\">RED</a>\n"
    "<a href=\"/?green!\">GREEN</a>\n"
    "<a href=\"/?blue!\">BLUE</a>\n"
    "<a href=\"/?cyan!\">CYAN</a>\n"
    "<a href=\"/?purple!\">PURPLE</a>\n"
    "<a href=\"/?yellow!\">YELLOW</a>\n"
    "<a href=\"/?curtainClose!\">CURTAINCLOSE</a>\n"
    "<a href=\"/?curtainOpen!\">CURTAINOPEN</a>\n"
    "<a href=\"/?brightness!\">BRIGHTNESS</a>\n"
    "<a href=\"/?l!\">LEDON</a>\n"
    "<a href=\"/?f!\">LEDOFF</a>\n"
    
    "</BODY>\n"
    "</HTML>\n"
  ));
}

and then use it like:

printIndexHtml(client); // print to the remote client or...
printIndexHtml(Serial); // print to the serial for debug purposes

after running this for the call above i keep receiving this in serial monitor:

        while (c != endMark && inNum < maxNum && comingIn == true) {
          char c = client.read();
          charRead[inNum] += c;
          //store characters to string
          //Serial.print(c);
          inNum ++;
          c = NULL; // '\0' is better; NULL is for pointers. No need to set c to 0 anyway, it will be overwritten by client.read().
          Serial.println(charRead); // Don't print out the whole buffer inside of the loop, print it afterwards.
          //delay(2);
          client.flush(); // What's this for, why are you doing it in the loop?
        }
        // Debug print charRead here, but make sure you terminate it with null, ie. '\0', first

Provide the full serial output after making any changes.