title: Arduino - How can i get a string command and match it with if statements?
body: <p>I have this following code, which is working for any string to send and receive <code>hello world</code>. But how can i send specific string and use if then else ?</p>
  
  <p>for example, when i send following its always sending hello world only but how can i do </p>
  
  <pre><code>echo "command1" | nc -4u localhost 21
  echo "command2  | nc -4u localhsot 21
  </code></pre>
  
  <p>on receive i want to parse them with if then else but its not working:</p>
  
  <pre><code>if ( packetBuffer == "command1" ) { 
  
  else if ( packetBuffer == "command2") { 
  
  } else {
  
  }
  </code></pre>
  
  <p>code: </p>
  
  <pre><code>#include &lt;SPI.h&gt;
  #include &lt;Ethernet.h&gt;
  #include &lt;EthernetUdp.h&gt;
  
  byte mac[]={0xDE, 0xAD, 0xBE, 0xEF, 0xAD, 0xDE};
  IPAddress ip(192,168,1,2);
  unsigned int localPort = 21;
  
  char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
  char  ReplyBuffer[] = "hello world";
  EthernetUDP Udp;
  
  char          r1[] = "1";
  char          r2[] = "2";
  char          r3[] = "3";
  
  void setup() {
    Ethernet.begin(mac,ip);
    Udp.begin(localPort);
  }
  
  void loop() {
    int packetSize = Udp.parsePacket();
    if(packetSize) {
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
      Udp.write(packetBuffer);
  
        if ( !strcmp(packetBuffer, "command1") ) {
          Udp.write(r1);
        } else if ( !strcmp(packetBuffer, "command2") ) {
          Udp.write(r2);
        } else {
          Udp.write(r3);
        }
  
      Udp.endPacket();
    }
    delay(10);
  }
  </code></pre>