OK, I have my simplified app doing apparently the same thing with a small Ethernet/RS485 adapter driving a microcontroller that should be pretty close to what my target at work looks like.
The Ethernet/RS-485 adapter is configured to accept one client with no timeout (for now).
Here is my test environment:
Laptop runs 2 copies of the app, one under debug, the other runs the exe.
I also have wireshark running, looking for ip traffic to and from the Ethernet adapter.
The Ethernet/RS-485 adapter is connected to the uC board via RS-485. The serial protocol is a simple command/response protocol originally knows as the SABus protocol (framing bytes, parity bits and checksum).
I first connect the exe to my target (the first 3 lines on the Wireshark screen shot below, above the first red line) and send a command/get a response (the next 4 lines, between the two red lines). The default command "0" (ID query) is sent when you click the Send button.
Then the second copy of the app (the debug one) tries to connect to the same socket (SYN, SYN-ACK, ACK). My app says it is connecting (Connect button turns green) but the server is clearly closing the connection (FIN-ACK-FIN-ACK, the lines below the second red line) and neither AStream_Error or AStream_Terminated fire and there is no data going out when I click the Send button.
After I did this, I added the Log( xxxx ) statements in the Terminated and Error events and tried again and this time the debug app crashed with this error message:
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Trying to connect to: 192.168.1.10
b4xmainpage._astream_terminated (java line: 199)
java.lang.RuntimeException: Object should first be initialized (Exception).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4a.objects.B4AException.getMessage(B4AException.java:38)
at b4j.example.b4xmainpage._astream_terminated(b4xmainpage.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.BA$3.run(BA.java:264)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
I am puzzled by the "java.lang.RuntimeException: Object should first be initialized (Exception)" message since I have the AStream_Terminated event declared, even though it does not seem to have been firing since there is no message in the log.
The exe app is still running and connected and messages still go back and forth.
I have attached the project to the first post in this thread.
If you want to play with it, I can worm the target through the firewall and give you a domain name/port via private message so you can try.