1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Close the socket.

This commit is contained in:
Cedric Beust 2016-04-28 05:21:59 -08:00
parent f79d9f9497
commit e6a2ad98f7
2 changed files with 18 additions and 16 deletions

View file

@ -5,9 +5,10 @@ import java.io.PrintWriter
import java.net.Socket
fun main(argv: Array<String>) {
val socket = Socket("localhost", 1234)
Socket("localhost", 1234).use { socket ->
(PrintWriter(socket.outputStream, true)).use { out ->
out.println("""{ "name" : "getDependencies", "buildFile":
"/Users/beust/kotlin/kobalt/kobalt/src/${Constants.BUILD_FILE_NAME}"}""")
}
}
}

View file

@ -112,7 +112,7 @@ class ServerProcess {
}
try {
val socket = Socket("localhost", result)
Socket("localhost", result).use { socket ->
val outgoing = PrintWriter(socket.outputStream, true)
val c: String = """{ "name": "ping"}"""
outgoing.println(c)
@ -125,6 +125,7 @@ class ServerProcess {
if (received["name"].asString == "ping") {
result = properties.getProperty(KEY_PORT).toInt()
}
}
} catch(ex: IOException) {
log(1, "Couldn't connect to current server, launching a new one")
Thread.sleep(1000)