mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -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.InputStreamReader
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
import java.net.ServerSocket
|
import java.net.ServerSocket
|
||||||
|
import java.net.SocketException
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
|
||||||
public class KobaltServer @Inject constructor(val args: Args, val executors: KobaltExecutors,
|
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
|
val portNumber = args.port
|
||||||
|
|
||||||
log(1, "Starting on port $portNumber")
|
log(1, "Starting on port $portNumber")
|
||||||
|
var quit = false
|
||||||
val serverSocket = ServerSocket(portNumber)
|
val serverSocket = ServerSocket(portNumber)
|
||||||
|
while (! quit) {
|
||||||
val clientSocket = serverSocket.accept()
|
val clientSocket = serverSocket.accept()
|
||||||
outgoing = PrintWriter(clientSocket.outputStream, true)
|
outgoing = PrintWriter(clientSocket.outputStream, true)
|
||||||
if (pending.size() > 0) {
|
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))
|
val ins = BufferedReader(InputStreamReader(clientSocket.inputStream))
|
||||||
|
try {
|
||||||
var inputLine = ins.readLine()
|
var inputLine = ins.readLine()
|
||||||
while (inputLine != null) {
|
while (!quit && inputLine != null) {
|
||||||
log(1, "Received $inputLine")
|
log(1, "Received $inputLine")
|
||||||
|
if (inputLine == "Quit") {
|
||||||
|
log(1, "Quitting")
|
||||||
|
quit = true
|
||||||
|
} else {
|
||||||
runCommand(inputLine)
|
runCommand(inputLine)
|
||||||
if (inputLine.equals("Bye."))
|
|
||||||
break;
|
|
||||||
inputLine = ins.readLine()
|
inputLine = ins.readLine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(ex: SocketException) {
|
||||||
|
log(1, "Client disconnected, resetting")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface Command {
|
interface Command {
|
||||||
fun run(jo: JsonObject)
|
fun run(jo: JsonObject)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue