Reduce ping timeout

This commit is contained in:
Trevor Slocum 2023-10-24 21:40:36 -07:00
parent 07e9c3dc1e
commit bd2cb2c880
2 changed files with 5 additions and 5 deletions

View file

@ -86,7 +86,7 @@ formatted responses are more easily parsed by computers.
- `pong <message>`
- Sent in response to server `ping` event to prevent the connection from timing out.
- Whether the client sends a `pong` command, or any other command, clients
must write some data to the server at least once every ten minutes.
must write some data to the server at least once every 40 seconds.
- `disconnect`
- Disconnect from the server.
@ -155,4 +155,4 @@ provide clients with the initial match state.
- `ping <message:text>`
- Sent to clients to prevent their connection from timing out.
- Whether the client replies with a `pong` command, or any other command,
clients must write some data to the server at least once every ten minutes.
clients must write some data to the server at least once every 40 seconds.

View file

@ -16,7 +16,7 @@ import (
"code.rocket9labs.com/tslocum/bgammon"
)
const clientTimeout = 10 * time.Minute
const clientTimeout = 40 * time.Second
var onlyNumbers = regexp.MustCompile(`^[0-9]+$`)
@ -200,7 +200,7 @@ func (s *server) handleConnection(conn net.Conn) {
func (s *server) handlePingClient(c *serverClient) {
// TODO only ping when there is no recent activity
t := time.NewTicker(time.Minute * 4)
t := time.NewTicker(30 * time.Second)
for {
<-t.C
@ -210,7 +210,7 @@ func (s *server) handlePingClient(c *serverClient) {
}
if len(c.name) == 0 {
c.Terminate("User did not send login command within 2 minutes.")
c.Terminate("User did not send login command within 30 seconds.")
t.Stop()
return
}