v2 / vlib / net / websocket / tests / autobahn / autobahn_client_wss.v
35 lines · 31 sloc · 1012 bytes · 2332ecff4811b8c97dfda8e825170e9397962519
Raw
1// use this test to test the websocket client in the autobahn test
2module main
3
4import net.websocket
5
6fn 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 := 'wss://localhost:9002/updateReports?agent=v-client'
13 uri := 'wss://autobahn_server_wss:9002/updateReports?agent=v-client'
14 mut ws := websocket.new_client(uri)!
15 ws.connect()!
16 ws.listen()!
17}
18
19fn handle_case(case_nr int) ! {
20 uri := 'wss://autobahn_server_wss:9002/runCase?case=${case_nr}&agent=v-client'
21 // uri := 'wss://localhost:9002/runCase?case=${case_nr}&agent=v-client'
22 mut ws := websocket.new_client(uri)!
23 ws.on_message(on_message)
24 ws.connect()!
25 ws.listen()!
26}
27
28fn on_message(mut ws websocket.Client, msg &websocket.Message) ! {
29 // autobahn tests expects to send same message back
30 if msg.opcode == .pong {
31 // We just wanna pass text and binary message back to autobahn
32 return
33 }
34 ws.write(msg.payload, msg.opcode) or { panic(err) }
35}
36