Created
April 28, 2020 10:53
-
-
Save fitomad/6350e3a2e563ca3d9d65c243fc601241 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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