olahol / melody

:notes: Minimalist websocket framework for Go
BSD 2-Clause "Simplified" License
3.75k stars 366 forks source link

how to keep a connecting, it always timeout after 1 minute #66

Open kent58909 opened 3 years ago

kent58909 commented 3 years ago

it always timeout.. not proxy via nginx, only melody + gin, the same code as your example...

this pic:

image

after 1 minute, timeout, disconnect, and reconnect...

CodeDing commented 1 year ago

@kent58909 it may be caused by the client implementing by gin framework which does not set the websocket's ping handler. If the session of the melody instance sends a pingMessage to the client, but the session does not received the pongMessage as response,then the underlying network connection will be corrupted.

Advise Try to find a solution that setting up the websocket's pingHandler in your client code which must send a pongMessage as the response to the peer.

I hope that it may be helpful for you.

jm20122012 commented 2 months ago

I ran into this issue today. I was using the gorilla websocket client, and had to explicitly create a reader goroutine to handle the server's ping message. You can reset the read deadline in the client every time the server sends its ping message.