You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to set up a persistent connection to a socketio server that might restart. If that happens, I want to reconnect without needing to redefine my methods, etc.
I've added a new item to Client to store the URL:
type Client struct {
....
url string //stores the url for this connection
....
And added a new redial function (I know it's an endless loop and it needs some waits, but it's OK for testing...)
func Redial(c *Client) {
var err error
tr := transport.GetDefaultWebsocketTransport()
for {
c.conn, err = tr.Connect(c.url)
if err == nil {
break
}
}
go inLoop(&c.Channel, &c.methods)
go outLoop(&c.Channel, &c.methods)
go pinger(&c.Channel)
}
Then, I've added this to my code:
socket.On(gosocketio.OnDisconnection, func(c *gosocketio.Channel) {
log.Println("Disconnected from server, trying to reconnect")
gosocketio.Redial(socket)
}
This works, other than the socket.IsAlive() method returns false. I'm so close, but I just can't seem to get this right! I'm happy if there's a much better way to handle this, but this is what I came up with. Any help would be appreciated
The text was updated successfully, but these errors were encountered:
I'm trying to set up a persistent connection to a socketio server that might restart. If that happens, I want to reconnect without needing to redefine my methods, etc.
I've added a new item to Client to store the URL:
And added a line to dial so it stores the URL:
And added a new redial function (I know it's an endless loop and it needs some waits, but it's OK for testing...)
Then, I've added this to my code:
This works, other than the
socket.IsAlive()
method returns false. I'm so close, but I just can't seem to get this right! I'm happy if there's a much better way to handle this, but this is what I came up with. Any help would be appreciatedThe text was updated successfully, but these errors were encountered: