mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
all: change optional to result of io (#16075)
This commit is contained in:
parent
6e46933c55
commit
f6844e9766
187 changed files with 1885 additions and 1874 deletions
|
@ -6,24 +6,24 @@ import term
|
|||
// this server accepts client connections and broadcast all messages to other connected clients
|
||||
fn main() {
|
||||
println('press ctrl-c to quit...')
|
||||
start_server()?
|
||||
start_server()!
|
||||
}
|
||||
|
||||
fn start_server() ? {
|
||||
fn start_server() ! {
|
||||
mut s := websocket.new_server(.ip6, 30000, '')
|
||||
// Make that in execution test time give time to execute at least one time
|
||||
s.ping_interval = 100
|
||||
s.on_connect(fn (mut s websocket.ServerClient) ?bool {
|
||||
s.on_connect(fn (mut s websocket.ServerClient) !bool {
|
||||
// Here you can look att the client info and accept or not accept
|
||||
// just returning a true/false
|
||||
if s.resource_name != '/' {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})?
|
||||
})!
|
||||
|
||||
// on_message_ref, broadcast all incoming messages to all clients except the one sent it
|
||||
s.on_message_ref(fn (mut ws websocket.Client, msg &websocket.Message, mut m websocket.Server) ? {
|
||||
s.on_message_ref(fn (mut ws websocket.Client, msg &websocket.Message, mut m websocket.Server) ! {
|
||||
// for _, cli in m.clients {
|
||||
for i, _ in m.clients {
|
||||
mut c := m.clients[i]
|
||||
|
@ -33,7 +33,7 @@ fn start_server() ? {
|
|||
}
|
||||
}, s)
|
||||
|
||||
s.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
|
||||
s.on_close(fn (mut ws websocket.Client, code int, reason string) ! {
|
||||
println(term.green('client ($ws.id) closed connection'))
|
||||
})
|
||||
s.listen() or { println(term.red('error on server listen: $err')) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue