From 00fc2943964b526cbdf008f566ed55ad83cbe7ca Mon Sep 17 00:00:00 2001 From: CodeSteak Date: Tue, 4 Jun 2019 16:10:11 +0200 Subject: [PATCH] set timeout for Server Connection --- .../org/hso/texturesyncclient/controller/net/Connection.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt index 1ce1531..9cf2ddc 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt @@ -6,6 +6,7 @@ import org.hso.texturesyncclient.model.Sha256 import org.hso.texturesyncclient.model.Texture import java.io.* import java.net.InetAddress +import java.net.InetSocketAddress import java.net.Socket import java.util.* @@ -23,7 +24,11 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { val o: DataOutputStream if (socket == null || !socket!!.isConnected) { - val sock = Socket(address, port) + val sock = Socket() + sock.soTimeout = 10_000 /*ms*/ + sock.keepAlive = true + sock.connect(InetSocketAddress(address, port), 1_000 /*ms*/) + i = DataInputStream(BufferedInputStream(sock.getInputStream())) o = DataOutputStream(BufferedOutputStream(sock.getOutputStream()))