2020-08-22 00:50:38 +02:00
|
|
|
// use this test to test the websocket client in the autobahn test
|
|
|
|
module main
|
|
|
|
|
|
|
|
import x.websocket
|
|
|
|
|
|
|
|
fn main() {
|
2020-12-28 06:25:46 +01:00
|
|
|
for i in 1 .. 304 {
|
2020-08-22 00:50:38 +02:00
|
|
|
println('\ncase: $i')
|
2020-12-28 06:25:46 +01:00
|
|
|
handle_case(i) or { println('error should be ok: $err') }
|
2020-08-22 00:50:38 +02:00
|
|
|
}
|
|
|
|
// update the reports
|
|
|
|
uri := 'ws://autobahn_server:9001/updateReports?agent=v-client'
|
2020-12-28 06:25:46 +01:00
|
|
|
mut ws := websocket.new_client(uri) ?
|
|
|
|
ws.connect() ?
|
|
|
|
ws.listen() ?
|
2020-08-22 00:50:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_case(case_nr int) ? {
|
|
|
|
uri := 'ws://autobahn_server:9001/runCase?case=$case_nr&agent=v-client'
|
2020-12-28 06:25:46 +01:00
|
|
|
mut ws := websocket.new_client(uri) ?
|
2020-08-22 00:50:38 +02:00
|
|
|
ws.on_message(on_message)
|
2020-12-28 06:25:46 +01:00
|
|
|
ws.connect() ?
|
|
|
|
ws.listen() ?
|
2020-08-22 00:50:38 +02:00
|
|
|
}
|
|
|
|
|
2020-12-28 06:25:46 +01:00
|
|
|
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
2020-08-22 00:50:38 +02: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
|
|
|
|
}
|
2020-12-28 06:25:46 +01:00
|
|
|
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
2020-08-22 00:50:38 +02:00
|
|
|
}
|