golang googollee/go-socket.io module pingtimeout automatically closing socket connections

91 Views Asked by At

I am performing socketio operations using googollee/go-socket.io on the golang side. Even though I set the pingtimeout and pinginterval settings when opening a connection, as long as the disconnect is not triggered, it shows as connected even if the internet connection of the device connected to the socket is disconnected. Therefore, devices that are not disconnected continue to appear connected to the socket. I have left the setting I made when opening the socket below. How can I close the socket connection automatically?

    options := &engineio.Options{
        PingTimeout:  60 * time.Second,
        PingInterval: 30 * time.Second,
    }
    server := socketio.NewServer(options)
    go func() {
        if err := server.Serve(); err != nil {
            log.Fatalf("socketio listen error: %s\n", err)
        }
    }()
    defer server.Close()
1

There are 1 best solutions below

5
On

maybe try to put the defer inside the func?

go func() {
        if err := server.Serve(); err != nil {
            log.Fatalf("socketio listen error: %s\n", err)
        }
 defer server.Close()
}()