diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index 3773463a..e778d645 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -149,9 +149,14 @@ open class Client(config: Configuration = Configuration when (remoteAddress) { "0.0.0.0" -> throw IllegalArgumentException("0.0.0.0 is an invalid address to connect to!") "loopback", "localhost", "lo", "" -> { - isIpcConnection = true - logger.info("Auto-changing network connection from $remoteAddress -> IPC") - this.remoteAddress = "ipc" + if (config.enableIpcForLoopback) { + isIpcConnection = true + logger.info("Auto-changing network connection from $remoteAddress -> IPC") + this.remoteAddress = "ipc" + } else { + isIpcConnection = false + this.remoteAddress = IPv4.LOCALHOST.hostAddress + } } "0x" -> { isIpcConnection = true @@ -159,14 +164,24 @@ open class Client(config: Configuration = Configuration } else -> when { IPv4.isLoopback(remoteAddress) -> { - logger.info("Auto-changing network connection from $remoteAddress -> IPC") - isIpcConnection = true - this.remoteAddress = "ipc" + if (config.enableIpcForLoopback) { + isIpcConnection = true + logger.info("Auto-changing network connection from $remoteAddress -> IPC") + this.remoteAddress = "ipc" + } else { + isIpcConnection = false + this.remoteAddress = IPv4.LOCALHOST.hostAddress + } } IPv6.isLoopback(remoteAddress) -> { - logger.info("Auto-changing network connection from $remoteAddress -> IPC") - isIpcConnection = true - this.remoteAddress = "ipc" + if (config.enableIpcForLoopback) { + isIpcConnection = true + logger.info("Auto-changing network connection from $remoteAddress -> IPC") + this.remoteAddress = "ipc" + } else { + isIpcConnection = false + this.remoteAddress = IPv6.LOCALHOST.hostAddress + } } else -> { isIpcConnection = false diff --git a/src/dorkbox/network/Configuration.kt b/src/dorkbox/network/Configuration.kt index 9405818f..ebe6212e 100644 --- a/src/dorkbox/network/Configuration.kt +++ b/src/dorkbox/network/Configuration.kt @@ -48,7 +48,6 @@ class ServerConfiguration : dorkbox.network.Configuration() { } open class Configuration { - /** * When connecting to a remote client/server, should connections be allowed if the remote machine signature has changed? * @@ -76,6 +75,12 @@ open class Configuration { */ var subscriptionPort: Int = 0 + /** + * Permit loopback connections to use IPC instead of UDP for communicating. IPC is about 4x faster than UDP in loopback situations. + * + * This configuration only affects the client + */ + var enableIpcForLoopback: Boolean = true /** * How long a connection must be disconnected before we cleanup the memory associated with it