diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt index 88b22fd1..7422c493 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt @@ -5,9 +5,10 @@ import java.io.PrintWriter import java.net.Socket fun main(argv: Array) { - val socket = Socket("localhost", 1234) - (PrintWriter(socket.outputStream, true)).use { out -> - out.println("""{ "name" : "getDependencies", "buildFile": - "/Users/beust/kotlin/kobalt/kobalt/src/${Constants.BUILD_FILE_NAME}"}""") + 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}"}""") + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt index 21963d43..2b011334 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt @@ -112,18 +112,19 @@ class ServerProcess { } try { - val socket = Socket("localhost", result) - val outgoing = PrintWriter(socket.outputStream, true) - val c: String = """{ "name": "ping"}""" - outgoing.println(c) - val ins = BufferedReader(InputStreamReader(socket.inputStream)) - var line = ins.readLine() - val jo = JsonParser().parse(line) as JsonObject - val jsonData = jo["data"]?.asString - val dataObject = JsonParser().parse(jsonData) as JsonObject - val received = JsonParser().parse(dataObject["received"].asString) as JsonObject - if (received["name"].asString == "ping") { - result = properties.getProperty(KEY_PORT).toInt() + Socket("localhost", result).use { socket -> + val outgoing = PrintWriter(socket.outputStream, true) + val c: String = """{ "name": "ping"}""" + outgoing.println(c) + val ins = BufferedReader(InputStreamReader(socket.inputStream)) + var line = ins.readLine() + val jo = JsonParser().parse(line) as JsonObject + val jsonData = jo["data"]?.asString + val dataObject = JsonParser().parse(jsonData) as JsonObject + val received = JsonParser().parse(dataObject["received"].asString) as JsonObject + 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")