mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Server loop.
This commit is contained in:
parent
9310283b16
commit
1fda17b8b6
1 changed files with 27 additions and 16 deletions
|
@ -15,6 +15,7 @@ import java.io.BufferedReader
|
|||
import java.io.InputStreamReader
|
||||
import java.io.PrintWriter
|
||||
import java.net.ServerSocket
|
||||
import java.net.SocketException
|
||||
import java.nio.file.Paths
|
||||
|
||||
public class KobaltServer @Inject constructor(val args: Args, val executors: KobaltExecutors,
|
||||
|
@ -26,7 +27,9 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
val portNumber = args.port
|
||||
|
||||
log(1, "Starting on port $portNumber")
|
||||
var quit = false
|
||||
val serverSocket = ServerSocket(portNumber)
|
||||
while (! quit) {
|
||||
val clientSocket = serverSocket.accept()
|
||||
outgoing = PrintWriter(clientSocket.outputStream, true)
|
||||
if (pending.size() > 0) {
|
||||
|
@ -37,15 +40,23 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
}
|
||||
}
|
||||
val ins = BufferedReader(InputStreamReader(clientSocket.inputStream))
|
||||
try {
|
||||
var inputLine = ins.readLine()
|
||||
while (inputLine != null) {
|
||||
while (!quit && inputLine != null) {
|
||||
log(1, "Received $inputLine")
|
||||
if (inputLine == "Quit") {
|
||||
log(1, "Quitting")
|
||||
quit = true
|
||||
} else {
|
||||
runCommand(inputLine)
|
||||
if (inputLine.equals("Bye."))
|
||||
break;
|
||||
inputLine = ins.readLine()
|
||||
}
|
||||
}
|
||||
} catch(ex: SocketException) {
|
||||
log(1, "Client disconnected, resetting")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Command {
|
||||
fun run(jo: JsonObject)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue