mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
x.websocket: move to net.websocket module (#10648)
This commit is contained in:
27
vlib/net/websocket/tests/autobahn/autobahn_server.v
Normal file
27
vlib/net/websocket/tests/autobahn/autobahn_server.v
Normal file
@@ -0,0 +1,27 @@
|
||||
// use this to test websocket server to the autobahn test
|
||||
module main
|
||||
|
||||
import net.websocket
|
||||
|
||||
fn main() {
|
||||
mut s := websocket.new_server(.ip6, 9002, '/')
|
||||
s.on_message(on_message)
|
||||
s.listen() or { panic(err) }
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri) ?
|
||||
ws.on_message(on_message)
|
||||
ws.connect() ?
|
||||
ws.listen() ?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or { panic(err) }
|
||||
}
|
||||
Reference in New Issue
Block a user