recws-org / recws

Reconnecting WebSocket is a websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped and keeps the connection alive - thread safe!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do you send a message on reconnect?

pacedavis opened this issue · comments

I need to send a login message when the connection is reestablished. How do I do this?

You can just use the subscribeHandler

Thank you Lucas for the very quick reply! Can you give me a quick example of how I do that? I see hasSubscribeHandler, not sure where I capture events for subscribeHandler. Please excuse my ignorance.

You can just set the SubscribeHandler as field: https://github.com/recws-org/recws/blob/master/recws.go#L43

Let me know if this does not help - then i will create a quick example for you tomorrow

Should look like this:

	var ws = &recws.RecConn{
		RecIntvlMax: 10 * time.Minute,
		SubscribeHandler: func() error {
			// send your login message here
		},
		KeepAliveTimeout: 10 * time.Second,
	}

Awesome. Thank you so much!