We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to close websocket conn from other function? Why c.Close() dont work?
package main import ( "github.com/gofiber/contrib/websocket" "github.com/gofiber/fiber/v2" "log" ) type conns struct { connections map[string]*websocket.Conn } func someChecker(connections *conns) { log.Println("starting some checker") for { for key, value := range connections.connections { if key != "some_check" { err := value.Close() if err != nil { log.Println("error closing connection", err) } else { log.Println("connection closed") // Prints closed but not closed } delete(connections.connections, key) } } } } func main() { connections := conns{connections: make(map[string]*websocket.Conn)} app := fiber.New() app.Get( "/ws", websocket.New( func(c *websocket.Conn) { connections.connections[c.RemoteAddr().String()] = c for { _, _, err := c.ReadMessage() if err != nil { break } } }, ), ) go someChecker(&connections) log.Fatal(app.Listen(":3000")) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Question Description
How to close websocket conn from other function? Why c.Close() dont work?
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: