Fix app running check [stage]

This commit is contained in:
crschnick
2025-07-10 17:18:23 +00:00
parent 5f92e37d7c
commit 4dbeb5bba8
3 changed files with 18 additions and 4 deletions

View File

@@ -5,11 +5,13 @@ import io.xpipe.core.FilePath;
import io.xpipe.core.OsType;
import io.xpipe.core.XPipeDaemonMode;
import io.xpipe.core.XPipeInstallation;
import lombok.SneakyThrows;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;
@@ -18,14 +20,25 @@ import java.util.List;
*/
public class BeaconServer {
@SneakyThrows
public static boolean isReachable(int port) {
var local = Inet4Address.getByAddress(new byte[]{0x7f, 0x00, 0x00, 0x01});
try (var socket = new Socket()) {
socket.connect(
new InetSocketAddress(Inet4Address.getByAddress(new byte[] {0x7f, 0x00, 0x00, 0x01}), port), 5000);
return true;
InetSocketAddress adress = new InetSocketAddress(local, port);
socket.connect(adress, 5000);
} catch (Exception e) {
return false;
}
// If there's some kind of networking tool interfering with sockets by for example proxying socket connections
// The previous connect might succeed even though nothing is running.
// To be sure, check that the socket is indeed occupied
try (var ignored = new ServerSocket(port, 0, local)) {
return false;
} catch (Exception e) {
return true;
}
}
private static List<String> toProcessCommand(String toExec) {

View File

@@ -145,3 +145,4 @@ The HTTP API has been improved in various areas. The action system is integrated
- Fix text color on hover having low contrast in some themes
- Fix connection search freezing on Ubuntu systems with LXD snap stub installed
- Fix freeze after waking up the local system from a long hibernation
- Fix application not starting up if some antivirus interfered with local socket connections

View File

@@ -1 +1 @@
17.0-15
17.0-16