Skip to content
New issue

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

Is rate limiting messages possible? #61

Open
darienmiller88 opened this issue Jun 27, 2021 · 0 comments
Open

Is rate limiting messages possible? #61

darienmiller88 opened this issue Jun 27, 2021 · 0 comments

Comments

@darienmiller88
Copy link

What's the best way to protect against someone on the front end simply using while(true){client.emit('i am spammer', true)} to flood my server with messages?

router := chi.NewRouter()
socketServer := socketio.NewServer(nil)
router.Use(httprate.LimitByIP(1, 5 * time.Second))//This only rate limits incoming client connections, not the client messages.

socketServer.OnConnect("/", func(c socketio.Conn) error {
        fmt.Println(c.ID() + ": connected")
        c.Join("public_chat")
        return nil
})

socketServer.OnEvent("/", "from_client", func(c socketio.Conn, message string) {
        fmt.Println(c.ID()+":", message)
})

router.Handle("/", socketServer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant