1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

x.websocket: server broadcast plus examples (#7922)

This commit is contained in:
Tomas Hellström
2021-01-06 15:43:54 +01:00
committed by GitHub
parent 42e60b8e27
commit f9a873736e
5 changed files with 112 additions and 5 deletions

View File

@ -333,11 +333,9 @@ pub fn (mut ws Client) close(code int, message string) ? {
close_frame[i + 2] = message[i]
}
ws.send_control_frame(.close, 'CLOSE', close_frame) ?
ws.send_close_event(code, message)
unsafe { close_frame.free() }
} else {
ws.send_control_frame(.close, 'CLOSE', []) ?
ws.send_close_event(code, '')
}
ws.fragments = []
}

View File

@ -10,7 +10,6 @@ import rand
// Server represents a websocket server connection
pub struct Server {
mut:
clients map[string]&ServerClient // clients connected to this server
logger &log.Log // logger used to log
ls net.TcpListener // listener used to get incoming connection to socket
accept_client_callbacks []AcceptClientFn // accept client callback functions
@ -20,8 +19,8 @@ pub:
port int // port used as listen to incoming connections
is_ssl bool // true if secure connection (not supported yet on server)
pub mut:
ping_interval int = 30
// interval for sending ping to clients (seconds)
clients map[string]&ServerClient // clients connected to this server
ping_interval int = 30 // interval for sending ping to clients (seconds)
state State // current state of connection
}