'Trying to connect ESP32CAM over http and tcp/ip at the same time

I am trying to connect my ESP32CAM module over http and TCP/IP at the same time for my school project. It too important to me please help.

What I've tried is write some code in the loop of CameraWebServer example.

void loop() {

  WiFiClient client = wifiServer.available();

  if (client) { 
    while (client.connected()) {
      delay(10);
      Serial.println("test");
      if(client.available()>0) {
        c = client.read();

         if(c == 'm')
        {
          Serial.println(timestamp() + "12 HIGH, 13 LOW");
          client.println(timestamp() + "12 HIGH, 13 LOW");
          digitalWrite(12, HIGH);
          digitalWrite(13, LOW);
          
          time_1 = millis();
          time_2 = millis() + 1000;
          c = 0; 
          
          while(client.connected())
          {
            if(millis() >= time_1 + 1000){
                Serial.println(timestamp() + "12 LOW, 13 HIGH");
                client.println(timestamp() + "12 LOW, 13 HIGH");
                digitalWrite(12, LOW);
                digitalWrite(13, HIGH);
                time_1 +=2000;
            }
            if(millis() >= time_2 + 1000){
                Serial.println(timestamp() + "12 HIGH, 13 LOW");
                client.println(timestamp() + "12 HIGH, 13 LOW");
                digitalWrite(12, HIGH);
                digitalWrite(13, LOW);
                time_2 +=2000;
            }
            
            if(client.available()>0)
            {
              c = client.read();
            }
            if(c == 'z')
            {
              c = 0; //yeni data için sıfırlama.
              Serial.println(timestamp() + "Loop is stopped.");
              client.println(timestamp() + "Loop is stopped.");
              digitalWrite(12, LOW);
              digitalWrite(13, LOW);
              break;
            }
          }
        }
      }
    }
  }







        
  

}

And when I tried to open xxx.xxx.xx.xx:81/stream URL everything works fine. I can connect to TCP server while I watch the stream. But when I open xxx.xxx.xx.xx(like 192.168.43.88) website from now on I cannot open TCP connection while I am watching the stream. ESP32 keeps diconnecting new clients. Can someone explain why this happening or how can I fix that ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source