set timeout for Server Connection

This commit is contained in:
CodeSteak 2019-06-04 16:10:11 +02:00
parent a3a86cf913
commit 00fc294396
1 changed files with 6 additions and 1 deletions

View File

@ -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()))