Android Question Socket client know when server disconnect or stop

max123

Well-Known Member
Licensed User
Longtime User
Hi all,

My B4A app control a 3D Printer by connecting to an ESP32 over TCP socket.

My app is a client and ESP32 is a server.

The ESP32 is connected to a 3D printer over USB cable with USB Host Shield, so ESP32 acts as true host (the same than pc) and can control a 3D Printer, even receive feedback that is sent to my app. ESP32 even have uSD card slot where read gcode files transferred from my app.

All this works. Now the problem is:
If I connect my app (client) to ESP32 (server), when I disconnect or just close the app, ESP32 know a disconnection without problems.

This do not happen on client side, if I switch off ESP32 while client is connected, my app do not know that server goes offline.

I use AsyncStreams and SocketAStreams_Terminated or SocketAStreams_Error do not fires at all.

Do this happen because it is a client and not a server ?
How I can know that server stay online or offline or just disconnect the client ?
I need to use a timer to continue ping the server to know it ? I want avoid to do this, there are other solutions ?

Many thanks
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
So, I've recreated a full simple code to test outside my project,
but AStream_Error do not fires when I switch off ESP, even after I waited 10-20-30 minutes.

This is tested with both ESP8266 and ESP32, on real device with Android 6 and on emulator with Android 12.

What is wrong please ?

Follow a simple sketch to create ESP8266 or ESP32 server
C++:
//#include <WiFi.h> // For ESP32
#include <ESP8266WiFi.h> // For ESP8266

const char* ssid = "your-ssid";
const char* pass = "your-pass";
const int SERVER_PORT = 11342;
WiFiServer server (SERVER_PORT);

void setup() {
   Serial.begin (115200);
   delay (2000);

   // We start by connecting to a WiFi network
   Serial.printf ("\n\nConnecting to %s\n", ssid);
   WiFi.begin (ssid, pass);
   while (WiFi.status() != WL_CONNECTED) {
      delay (500);
      Serial.print (".");
   }
   Serial.println ("");
   Serial.println ("WiFi connected.");
   Serial.println ("IP address: ");
   Serial.println (WiFi.localIP());
   server.begin();
}

void loop() {
   WiFiClient client = server.available();   // Listen for incoming clients
   if (client) {                             // If you get a client
      Serial.println ("Client connected");   // Print a message out the serial port
      while (client.connected()) { // Loop while the client connected
         yield(); // Required for ESP8266
      }
      Serial.println ("Client disconnected"); // Else client disconnected
   }
}

And a simple B4A code that is same as project posted on post #13:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
 
    Private AST As AsyncStreams
    Private Client As Socket
 
    Private Connected As Boolean = False
 
'    Private RemoteIP As String = "79.52.141.40"   ' Public IP Address
    Private RemoteIP As String = "192.168.178.36"  ' Local IP Address
    Private RemotePort As Int = 11342
 
    Private btnConnect As Button
    Private btnDisconnect As Button
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub btnConnect_Click
    ConnectToServer(RemoteIP, RemotePort)
End Sub

Sub btnDisconnect_Click
    CloseExistingConnection
End Sub

'''''''''''''''''''''''''''''''''''

Sub AST_Error
    Connected = False
    mLog("AST Error")
    AST_Terminated
End Sub

Sub AST_Terminated
    Connected = False
    mLog("AST Terminated")
    btnConnect.Enabled = True
    btnDisconnect.Enabled = False
End Sub

Sub AST_NewData (Buffer() As Byte)
    Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
    Log("Received " & Buffer.Length & " Bytes: " & s)
End Sub

''''''''''''''''''''''''''''''''''

Sub CloseExistingConnection
    If AST.IsInitialized Then AST.Close
    If Client.IsInitialized Then Client.Close
    Connected = False
    Log("IP - Connection Closed")
    btnConnect.Enabled = True
    btnDisconnect.Enabled = False
End Sub

Private Sub ConnectToServer(Host As String, Port As Int)
    If Connected = False Then
        Log("Trying to connect to: " & Host & ":" & Port)
        CloseExistingConnection
        Dim Client As Socket
        Client.Initialize("Client")
        Client.Connect(Host, Port, 10000)
        Wait For Client_Connected (Successful As Boolean)
        If Successful Then
            Connected = True
            AST.Initialize(Client.InputStream, Client.OutputStream, "AST")
            Log("IP - Successful Connect")
            ToastMessageShow("IP - Successful Connect", True)
            btnConnect.Enabled = False
            btnDisconnect.Enabled = True
        Else
            Log("IP - Failed to connect: " & LastException)
            ToastMessageShow("IP - Failed to connect: " & LastException, True)
        End If
    End If
End Sub

Sub mLog (s As String)
    Log(s)
    ToastMessageShow(s, True)
End Sub
 
Last edited:
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
with the arduino code you posted, app connects...
then I unplug the usb cable from the esp...
no AStream_Error in android log... even waiting for more than 20 sec.

The only difference I notice is that the esp in access point mode android returns the error
while in station mode (your arduino code) android no error return.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
My friend noticed me that is not good my While loop with yield() inside, may is this the problem here ? Note that this is different from my main project, this is the function I call in my main project, I call it from loop() every some milliseconds, as you can see it handle multiple clients, but is non this the issue, as you see it do not work even with a single client.
C++:
void GetSocketNewConnections() {

   //   LogMessage ("GetSocketNewConnections", true, false);

   uint8_t i;

   // Find free/disconnected spot
   for (i = 0; i < MAX_SRV_CLIENTS; i++) {
      //      if (i == 0) LogMessage (" ", true, false);
      //      LogMessage ("GET CLIENT " + String (i) + "  ->  " + String (serverClients[i].connected()), true, false);
      if (serverClients[i].connected()) {
         //         LogMessage ("CLIENT CONNECTED " + String (i) + "  ->  " + String (mSocketConnected[i]), true, false);
         if (!mSocketConnected[i] == true) {

            Beep (BEEP_FREQ_1, 80);
            mSocketConnected[i] = true;
            LogMessage ("\nClient [" + String (i + 1) + "] Connected", true, false);
            //            ShowMessageOnLCD ("   [" + String (i + 1) + "] Connected");
            ShowMessageOnLCD ("   [" + String (i + 1) + "] Connected", 1000);

            // Azzera in caso di riconnessione
            FileIsOpenForWrite = false;
            WaitingInfos = false;

            // Set socket parameters
            serverClients[i].setNoDelay (true);

            // Set and Get socket parameters
#if defined(ESP8266)
            serverClients[i].setSync (true); // VEDERE LA CONTROPARTE PER ESP32
            serverClients[i].setTimeout (120000);

            bool nodelay = serverClients[i].getNoDelay();
            Serial.printf ("TCP NODELAY: %s\n", nodelay ? "True" : "False");
            bool issync = serverClients[i].getSync();
            Serial.printf ("TCP SYNC: %s\n", issync ? "True" : "False");
            bool keepalive = serverClients[i].isKeepAliveEnabled();
            Serial.printf ("TCP_KEEPALIVE: %s\n", keepalive ? "True" : "False");
            uint16_t keepaliveidle = serverClients[i].getKeepAliveIdle();
            Serial.printf ("TCP KEEPALIVE IDLE: %d\n", keepaliveidle);
            uint16_t keepaliveinterval = serverClients[i].getKeepAliveInterval();
            Serial.printf ("TCP KEEPALIVE INTERVAL: %d\n", keepaliveinterval);
            uint8_t keepalivecount = serverClients[i].getKeepAliveCount();
            Serial.printf ("TCP KEEPALIVE COUNT: %d\n", keepalivecount);
#elif defined(ESP32)
            serverClients[i].setTimeout (120); // Seconds on ESP32

            int flag1 = 0;
            serverClients[i].getOption (0x01, &flag1);
            bool nodelay = flag1;
            Serial.printf ("TCP NODELAY: %s\n", nodelay ? "True" : "False");
            int keepalive = 0;
            serverClients[i].getOption (0x01, &keepalive);
            Serial.printf ("TCP KEEPALIVE: %d\n", keepalive);
#endif

            ////////////

            // No free/disconnected spot so reject

            // TEORICAMENTE LA SEGUENTE CONDIZIONE NON SI DOVREBBE MAI VERIFICARE PERCHÈ i NON PUÒ MAI ESSERE UGUALE A MAX_SRV_CLIENTS

            // Hints: server.available() is a WiFiClient with short-term scope when out of scope, a WiFiClient will
            // - flush() - all data will be sent
            // -  stop() - automatically too
            if (i == MAX_SRV_CLIENTS) {
               server.available().println ("Server is busy [Max clients reached]");
               LogMessage ("Server is busy with " + String (MAX_SRV_CLIENTS) + " active connections\n", true, true);
               Beep (1200, 100);
               Beep (1400, 100);
               Beep (1200, 100);
               Beep (1400, 200);
               ShowMessageOnLCD ("SERVER BUSY");
            }
         }
      } else {
         if (mSocketConnected[i] == true) {
            Beep (BEEP_FREQ_1, 50);
            mSocketConnected[i] = false;
            LogMessage ("\nClient [" + String (i + 1) + "] Disconnected", true, false);
            //            ShowMessageOnLCD ("  [" + String (i + 1) + "] Disconnected");
            ShowMessageOnLCD ("  [" + String (i + 1) + "] Disconnected", 1000);

            // Azzera in caso di riconnessione
            FileIsOpenForWrite = false;
            WaitingInfos = false;
         }
         serverClients[i] = server.available();
      }
   }
}
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
@Erel please, I need your experience here, or I will not exit from that situation.

Your suggestion 'heartbeat' is not applicable here because my app is complex and is timing sensible while 3D printer work.

AStream_Error do not fires at all for me even after minutes.
I compile with SDK 33 and run it on Android 6 device with latest 12.50 B4A version.
I even tried with emulator and Android 12 and I've the same results.

Please, can you try my simple project in post #13 ?

Many Thanks
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Hi @XorAndOr , I tried to implement heartbeat as Erel said, this seem to work but in strange way, and is very difficult to me to implement this on my main project because it is time critical and only the B4X main is around 14.000 lines of code, the full app around 38.000 lines of code.

Please do you have some suggestions to impove it or make the code more clear ?

I'm here to work, this is not my hobby and I cannot wait anymore, but peoples do not help, may they are to the sea
while I'm here to work on this, so I figured I need to do it myself. :(

Is not possible that 580 peoples read this thread and only 3-4 peoples replied. No problem, I help me myself ?

This is the B4X code:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
 
    Private AST As AsyncStreams
    Private Client As Socket
 
    Private Connected As Boolean = False
 
'    Private RemoteIP As String = "79.52.141.40"   ' Public IP Address
    Private RemoteIP As String = "192.168.178.66"  ' Local IP Address
    Private RemotePort As Int = 11342
 
    Private btnConnect As Button
    Private btnDisconnect As Button
 
    Dim Timer1 As Timer
    Dim t1 As Long
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Timer1.Initialize("Timer1", 1000)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub btnConnect_Click
    ConnectToServer(RemoteIP, RemotePort)
End Sub

Sub btnDisconnect_Click
    CloseExistingConnection
End Sub

'''''''''''''''''''''''''''''''''''

Sub AST_Error
    Connected = False
    mLog("AST Error", True)
    AST_Terminated
End Sub

Sub AST_Terminated
    Connected = False
    mLog("AST Terminated", True)
    btnConnect.Enabled = True
    btnDisconnect.Enabled = False
End Sub

Sub AST_NewData (Buffer() As Byte)
    Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
    Log("Received " & Buffer.Length & " Bytes: " & s)
    If s = "ALIVE" Then t1 = DateTime.Now
End Sub

''''''''''''''''''''''''''''''''''

Sub CloseExistingConnection
    If AST.IsInitialized Then AST.Close
    If Client.IsInitialized Then Client.Close
    Connected = False
    Log("IP - Connection Closed")
    btnConnect.Enabled = True
    btnDisconnect.Enabled = False
End Sub

Private Sub ConnectToServer(Host As String, Port As Int)
    If Connected = False Then
        CloseExistingConnection
        mLog("Trying to connect to: " & Host & ":" & Port, True)
        Client.Initialize("Client")
        Client.Connect(Host, Port, 10000)
        Wait For Client_Connected (Successful As Boolean)
        If Successful Then
            AST.Initialize(Client.InputStream, Client.OutputStream, "AST")
            ServerConnected(True)
        Else
            ServerConnected(False)
        End If
    End If
End Sub

Sub Timer1_Tick
'    Log("TIMER TICK")
    Dim t2 As Long = DateTime.now - t1
    Log("T2: " & t2)
    If Connected And t2 > 2000 Then ServerConnected(False)
End Sub

Sub ServerConnected(b As Boolean)
    If b Then
        mLog ("SERVER CONNECTED", False)
        Connected = True
        btnConnect.Enabled = False
        btnDisconnect.Enabled = True
        Timer1.Enabled = True
    Else
        mLog ("SERVER DISCONNECTED OR FAILED TO CONNECT: " & LastException.Message, True)
        Connected = False
        btnConnect.Enabled = True
        btnDisconnect.Enabled = False
        Timer1.Enabled = False
    End If
End Sub

Sub mLog (s As String, b As Boolean)
    Log(s)
    ToastMessageShow(s, b)
End Sub

..... and this is the ESP sketch:
C++:
#include <WiFi.h> // For ESP32
//#include <ESP8266WiFi.h> // For ESP8266

const char* ssid = "your ssid";
const char* pass = "your pass";
const int SERVER_PORT = 11342;
WiFiServer server (SERVER_PORT);

void setup() {
   Serial.begin (115200);
   delay (2000);

   // We start by connecting to a WiFi network
   Serial.printf ("\n\nConnecting to %s\n", ssid);
   WiFi.begin (ssid, pass);
   while (WiFi.status() != WL_CONNECTED) {
      delay (500);
      Serial.print (".");
   }
   Serial.println ("");
   Serial.println ("WiFi connected.");
   Serial.println ("IP address: ");
   Serial.println (WiFi.localIP());
   server.begin();
}

void loop() {
   WiFiClient client = server.available();   // Listen for incoming clients
   if (client) {                             // If you get a client,
      Serial.println ("Client connected");   // Print a message out the serial port
      while (client.connected()) { // Loop while the client connected
         if(millis() % 1000 == 0) client.print("ALIVE");
         yield(); // Required for ESP8266
      }
      Serial.println ("Client disconnected"); // Else client disconnected
   }
}
 
Last edited:
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
Please do you have some suggestions to impove it or make the code more clear ?
I'm sorry that you have not found a solution,
the tests that I was able to do in my knowledge I have done.
here there are 2 problems:
the return of the error when disconnecting the esp...
and the other significant problem is that the esp code is in c++,
here i really don't have knowledge of this language.
However I will do some testing of the code you posted.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
I'm sorry that you have not found a solution,
the tests that I was able to do in my knowledge I have done.
here there are 2 problems:
the return of the error when disconnecting the esp...
and the other significant problem is that the esp code is in c++,
here i really don't have knowledge of this language.
However I will do some testing of the code you posted.
Do not matter, the C++ code is simple as you see.... to do it with B4R. Is just a simple TCP server that listen on, and send ALIVE every second.
I want to tank you for your help. Many thanks.

For my question I just refer to B4A code.
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
but peoples do not help, may they are to the sea

Non proprio "to the sea", io sono in montagna :)

I'm sorry but I can't help you because I don't have an ESP32 board for to try it

I think that the "heartbeat" solution may be valid, I solved a similar problem with this system many years ago

Do you connect phone with ESP32 with wifi or with USB cable ?
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Non proprio "to the sea", io sono in montagna
By sea I meant holidays, I got the wrong word... I'm sorry....
Per mare intendevo ferie, ho sbagliato la parola... ti chiedo scusa....

Do you connect phone with ESP32 with wifi or with USB cable ?
I connect ESP32 with WiFi TCP Socket.
I found another Italian. Great. Only italians repies.

Thanks @sirjo66, I'm tinkering with it but I don't really like the solution of having to continuously send an ALIVE message from the server to the client to find out if the server has disconnected. I would much rather ASyncStream_Error go to make things easier. The fact is that 'heartbeat' can work on all devices, while ASyncStream_Error is not known....

Grazie @sirjo66, ci sto smanettando ma non mi piace molto la soluzione di dover continuamente mandare un messaggio ALIVE dal server al client per scoprire se il server si è disconnesso. Avrei tanto preferito che andasse ASyncStream_Error per rendere le cose piu semplici. Il fatto è che 'heartbeat' può funzionare su tutti i devices, mentre ASyncStream_Error no si sa....

Ciao, grazie per la risposta e buone ferie.
 
Last edited:
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
only method I was able to do is to send a string every 2 seconds or more to android
in android AST_NewData (Buffer() As Byte) you should check this string,
since the esp disconnects android doesn't receive it anymore.
this is little but I don't know more
B4X:
void loop() {
   WiFiClient client = server.available();   // Listen for incoming clients
   if (client) {                             // If you get a client
      Serial.println ("Client connected");   // Print a message out the serial port
      while (client.connected()) { // Loop while the client connected
         yield(); // Required for ESP8266         
        
         delay (2000);         
         client.write("Here all OK");// >>>> Send to Android
        
      }     
      Serial.println ("Client disconnected"); // Else client disconnected
   }
}
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Ok, I can help you, but as I wrote I don't have an ESP32 board (but I have 2 phone), so ........

Make a little project in B4A that emulate ESP32 server so I can install it in phone server.
Then, another project for client phone
Client send message to server and server answer.
Then, I poweroff phone server (ok, don't need poweroff, I switch off wifi connection) and so I can test what happen on client phone

Warning: heartbeat system is that client send a "beat" to server and server answer, not as you wrote !!
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
only method I was able to do is to send a string every 2 seconds or more to android
in android AST_NewData (Buffer() As Byte) you should check this string,
since the esp disconnects android doesn't receive it anymore.
this is little but I don't know more
B4X:
void loop() {
   WiFiClient client = server.available();   // Listen for incoming clients
   if (client) {                             // If you get a client
      Serial.println ("Client connected");   // Print a message out the serial port
      while (client.connected()) { // Loop while the client connected
         yield(); // Required for ESP8266        
       
         delay (2000);        
         client.write("Here all OK");// >>>> Send to Android
       
      }    
      Serial.println ("Client disconnected"); // Else client disconnected
   }
}
Because do you set 2 seconds ? This works for me with just one second. See my last code. The problem is that I cannot make it smaller time because B4A get false disconnections.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Ok, I can help you, but as I wrote I don't have an ESP32 board (but I have 2 phone), so ........

Make a little project in B4A that emulate ESP32 server so I can install it in phone server.
Then, another project for client phone
Client send message to server and server answer.
Then, I poweroff phone server (ok, don't need poweroff, I switch off wifi connection) and so I can test what happen on client phone

Warning: heartbeat system is that client send a "beat" to server and server answer, not as you wrote !!
Great, I will try it now to emulate ESP32 by code and post here to you.
Note that this also work with ESP8266 but may you don't have it.

Warning: heartbeat system is that client send a "beat" to server and server answer, not as you wrote !!
Mmmmm chatGPT and Google Bard says that server send alive message to a client and client check if the message continue to arrive, if not it is disconnected.
You are sure for this ? AI is wrong ?

I wanted that Erel brain is cloned to chatGPT so it can help any time I need help, but probably this is not possible.
I need to ask Erel if that is possible :D

Thanks @sirjo66
 
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
No, AI don't wrong, but there isn't only a system to develop a heartbeat.
If you already have a working master-client system, I think that is more simple to add a new request in the protocol
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
I tried it with Android (server) and Android (client), that way the sub AStream_Error is fired, but from ESP32 (server) and Android (client) do not. Tested even wirh ESP8266 but same result. Please help to solve it.
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If I connect my app (client) to ESP32 (server), when I disconnect or just close the app, ESP32 know a disconnection without problems.
Because in both cases, the TCP connections were cleaned up properly, with the client app/Android properly closing the connections. Try shutting down your device or disabling Wi-Fi/whatever network the phone is connected to on the device itself and see if the ESP notices the disconnect.
This do not happen on client side, if I switch off ESP32 while client is connected, my app do not know that server goes offline.
No, because the "server" is just shut down, without really closing the connection (turning power off = no more program running to notify anyone of the shutdown). So yes, powering off the ESP32 will not notify the client of the shutdown (how?).
but peoples do not help, may they are to the sea
Actually, the correct answer was already given to you in post #2. Implementing the keep-alive/heartbeat, if you encountered any issues, should then have been handled with another question.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks @OliverA now I cannot, I will respond you tomorrow.

Many Thanks for your interest
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
So @OliverA , is really instructive your reply, and you are 100% right on first point. ?

Seem to work as I supposed on post #3:
May it just get the disconnection if server side disconnect the client by software ?
Is different if I just switch off server side (ESP32) ?

Now may I know a bit better how it works, please correct me if I'm wrong here:

when switch off one side (the WiFi Network, not the connection by software or closing app), do no matter if it is a client or server, because I switch off the network it cannot notify other side (client or server). On ESP switch off it by removing power switch off the WiFi instantly, this is the same that switch off WiFi from Android.
This works the same even if ESP is the client that connect to Android server, right ?
Disconnect Android client (not tried) from ESP (by software) should fire AStream_Error, right ?

As your advices I did follow test:
- 1) Connect Android client to ESP server
- 2) Switch off Android WiFi, as you said ESP do not recognize disconnection
- 3) ESP recognize disconnection only next time Android try to reconnect to it
This is tested with real device (Android 6) and with emulator (Android 12) and do some result.

Next I did another test:
- 1) Connect Android client to ESP server
- 2) Reboot (or switch off/on) my router
- 3) ESP server get a regular disconnection after 5-6 seconds and notify it on printer LCD. Android client do not recognize it
- 4) Rebooting the router require a bit of time, like 2-3 minutes
- 5) After the network returns my ESP server detect that Public IP is changed, it check every 3 ninutes by doing a web request, show a notify on a printer LCD (see attached image) and control a printer buzzer to do a long beep (3 seconds) indicating that IP Address is changed. Next ESP show on a printer LCD 5 seconds Local IP Address and 5 seconds Public IP Address, intermittent these in an'infinite cycle until the client connect (note that max 3 clients are accepted, managed it by code, but probably in final stage I just use 1 client), this way the user can see the IP Address to connect to. In local both works, outside only public works, eventually on Android app I can use ResolveHost to use a DDNS instead of IP Address. Note that both methods need a router port-forwarding that point to ESP.
- 6) Network returned but Android remains connected and AStream_Error is not fired, even after 30 minutes, never fired at all

For this:
Actually, the correct answer was already given to you in post #2
I know it from start, Erel's answer was good to me, but I asked if it is possible to do it other ways:
I need to use a timer to continue ping the server to know it ? I want avoid to do this, there are other solutions ?
but this seem to be an issue in certain cases so 'heartbeat' always should work, if you disconnect, if no network signal occour, if router switch off and so....
I end up to make server that ping (simply send ALIVE) to client/s but this is not too different.
I wanted avoid to do 'heartbeat', because ESP-Android already exchange others data, even I need to check if this influences when I upload over WiFi to ESP the gcode file, that exchange a lots of data, may works, but not sure 100%, I need to test, may false disconnections can occour.
Even doing this, if ESP disconnect, Android know a disconnection after 1-2 seconds, if app send data, or user upload a gcode file etc... in these 1-2 seconds probably I've some strange things.
Note that ESP have uSD card, so files are upload here, and note that I even wrote this for Raspberry using B4J, it upload files to uSD, the same server works on desktop device and it upload to PC ssd.

Many Thanks
 

Attachments

  • P_20230817_014519[1].jpg
    P_20230817_014519[1].jpg
    215.3 KB · Views: 105
Last edited:
Upvote 0
Top