Dragos Rachieru
01/07/2021, 11:36 AM@JvmStatic
fun main(args: Array<String>) {
println("config sockets")
val client = HttpClient {
install(WebSockets)
}
println("starting")
runBlocking {
<http://client.ws|client.ws>(
method = HttpMethod.Get,
host = "0.0.0.0",
port = DefaultPort,
path = "/game?access_token=$token&game_type=DUEL",
request = {
header("Authorization", "Bearer $token")
}
) {
println("connected")
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
while (true) {
val scanner = Scanner(System.`in`)
val command = scanner.nextLine()
send(Frame.Text("${ServerFrameKey.PLACE.key}:$command"))
}
}
// Receive frame.
for (frame in incoming) {
when (frame) {
is Frame.Text -> println(frame.readText())
is Frame.Binary -> println(frame.readBytes())
}
}
}
}
}
This is the code for the clientfun send(session: WebSocketServerSession, command: CommandFrame<*>) {
val text = commandProcessor.process(command)
session.launch {
session.send(Frame.Text(text))
println("sent $text")
}
}
sent connected_room:60
in logs, but client prints nothingChris Fillmore
01/07/2021, 8:25 PMDragos Rachieru
02/01/2021, 7:53 AM