| 1 | // use this test to test the websocket client in the autobahn test |
| 2 | module main |
| 3 | |
| 4 | import net.websocket |
| 5 | |
| 6 | fn main() { |
| 7 | for i in 1 .. 304 { |
| 8 | println('\ncase: ${i}') |
| 9 | handle_case(i) or { println('error should be ok: ${err}') } |
| 10 | } |
| 11 | // update the reports |
| 12 | uri := 'ws://localhost:9001/updateReports?agent=v-client' |
| 13 | mut ws := websocket.new_client(uri)! |
| 14 | ws.connect()! |
| 15 | ws.listen()! |
| 16 | } |
| 17 | |
| 18 | fn handle_case(case_nr int) ! { |
| 19 | uri := 'ws://localhost:9001/runCase?case=${case_nr}&agent=v-client' |
| 20 | mut ws := websocket.new_client(uri)! |
| 21 | ws.on_message(on_message) |
| 22 | ws.connect()! |
| 23 | ws.listen()! |
| 24 | } |
| 25 | |
| 26 | fn on_message(mut ws websocket.Client, msg &websocket.Message) ! { |
| 27 | // autobahn tests expects to send same message back |
| 28 | if msg.opcode == .pong { |
| 29 | // We just wanna pass text and binary message back to autobahn |
| 30 | return |
| 31 | } |
| 32 | ws.write(msg.payload, msg.opcode) or { panic(err) } |
| 33 | } |
| 34 | |