2020-08-21 22:50:38 +00:00
|
|
|
// use this to test websocket server to the autobahn test
|
|
|
|
module main
|
|
|
|
|
2021-07-02 23:56:00 +00:00
|
|
|
import net.websocket
|
2020-08-21 22:50:38 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-06-13 20:53:38 +00:00
|
|
|
mut s := websocket.new_server(.ip6, 9002, '/')
|
2020-08-21 22:50:38 +00:00
|
|
|
s.on_message(on_message)
|
2021-02-28 23:18:14 +00:00
|
|
|
s.listen() or { panic(err) }
|
2020-08-21 22:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_case(case_nr int) ? {
|
|
|
|
uri := 'ws://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
2022-05-13 03:56:21 +00:00
|
|
|
mut ws := websocket.new_client(uri)?
|
2020-08-21 22:50:38 +00:00
|
|
|
ws.on_message(on_message)
|
2022-05-13 03:56:21 +00:00
|
|
|
ws.connect()?
|
|
|
|
ws.listen()?
|
2020-08-21 22:50:38 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 05:25:46 +00:00
|
|
|
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
2020-08-21 22:50:38 +00:00
|
|
|
// autobahn tests expects to send same message back
|
|
|
|
if msg.opcode == .pong {
|
|
|
|
// We just wanna pass text and binary message back to autobahn
|
|
|
|
return
|
|
|
|
}
|
2021-02-28 23:18:14 +00:00
|
|
|
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
2020-08-21 22:50:38 +00:00
|
|
|
}
|