| 1 | // use this to test websocket server to the autobahn test |
| 2 | module main |
| 3 | |
| 4 | import net.websocket |
| 5 | |
| 6 | fn main() { |
| 7 | mut s := websocket.new_server(.ip6, 9002, '/') |
| 8 | s.on_message(on_message) |
| 9 | s.listen() or { panic(err) } |
| 10 | } |
| 11 | |
| 12 | fn handle_case(case_nr int) ! { |
| 13 | uri := 'ws://localhost:9002/runCase?case=${case_nr}&agent=v-client' |
| 14 | mut ws := websocket.new_client(uri)! |
| 15 | ws.on_message(on_message) |
| 16 | ws.connect()! |
| 17 | ws.listen()! |
| 18 | } |
| 19 | |
| 20 | fn on_message(mut ws websocket.Client, msg &websocket.Message) ! { |
| 21 | // autobahn tests expects to send same message back |
| 22 | if msg.opcode == .pong { |
| 23 | // We just wanna pass text and binary message back to autobahn |
| 24 | return |
| 25 | } |
| 26 | ws.write(msg.payload, msg.opcode) or { panic(err) } |
| 27 | } |
| 28 | |