Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created April 28, 2020 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/6350e3a2e563ca3d9d65c243fc601241 to your computer and use it in GitHub Desktop.
Save fitomad/6350e3a2e563ca3d9d65c243fc601241 to your computer and use it in GitHub Desktop.
// MARK: - WebSockets -
func webSockets(_ app: Application) throws
{
app.webSocket("chat") { request, ws in
// Aqui el codigo que queramos ejecutar
// cuando un cliente se conecta
...
// String enviado por el cliente
ws.onText { ws, texto in
...
}
// Datos binarios enviado por el cliente
ws.onBinary { ws, data in
...
}
// El usuario ha cerrado la sesión.
// Basta con cerrar la pestaña del navegador
// para cerrar la sesión de WebSockets.
ws.onClose.whenComplete { result in
...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment