ESP 32 UDP keep connection

How to make UDP simple comunitcation protocol. Server based at ESP32 device backend will send request to ESP to udp port.

I need few steps

  1. Client -> Init connection to server ESP32 -> answer 100 Continue ESP32 -> anwer 401 Unauthorized (AUTH request)
  2. Client -> Send PW ESP32-> Check PW ESP32-> IF PW match answer 200 OK
  3. Client -> Request some data for example get temp ESP32 -> answer 20C ESP32 -> answer 200 OK (waiting for other command)
  4. Client -> request exit ESP32 -> answer 499 Bye

I've made simple connection class but it waiting just for one command ...

void udpServer() { char packetBuffer[255]; //buffer to hold incoming packet string cmd; string pw = "KADfM6E"; bool ello = false; bool auth = false; int packetSize = udp2.parsePacket(); while (packetSize) { Serial.println("NEW POCKET !!!"); int len = udp2.read(packetBuffer, 255); if (len > 0) { Serial.println("REPLAY"); udp2.beginPacket(udp2.remoteIP(), udp2.remotePort()); string cmd(packetBuffer); cmd.resize(len); if(!cmd.compare("ELLO") && !auth && !ello) { //NOT AUTH ASK PW udp2.println("401 Unauthorized"); udp2.printf("pocket %s lenth %d", cmd.c_str(), len); ello = true; } else if(!cmd.compare(pw) && !auth && ello){ auth = true; udp2.println("200 OK"); } else { udp2.println("100 Continue"); udp2.printf("pocket %s lenth %d", cmd.c_str(), len); }

udp2.endPacket(); } packetSize = udp2.parsePacket(); } }

Also im looking for Telnet or ssh server but all i've found is one side just for displaying (printing) but not for make some commands to arduino ...

do you try to reinvent the TCP protocol?

Maybe … you would recomend to use WiFiServer, WiFiClient classes ?

I need to make communication protocol … remote request parametes … get configs push new config run reboot save eprom etc …

https://arduino.stackexchange.com/questions/60819/esp8266-tcp-ip-communication/60821#60821