Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconnect after disconnect #14

Open
jeriveromartinez opened this issue Mar 30, 2019 · 1 comment
Open

reconnect after disconnect #14

jeriveromartinez opened this issue Mar 30, 2019 · 1 comment

Comments

@jeriveromartinez
Copy link

i need keep a stable connection between go client and node server, but after go client read the message this break teh connection.

2019/03/30 17:10:56 on message:hello1553987456281
2019/03/30 17:10:58 on disconnect

how i keep go client connected?

@Carminati7
Copy link

You need to add logic to the connect function you are using, i do try to connect again on disconnect and if the connection fail start to poll every other second.
Sample code to help

func connect() {
	opts := &socketio_client.Options{
		Transport: "websocket",
		Query:     make(map[string]string),
	}
	uri := "http://localhost:3001"
	client, err := socketio_client.NewClient(uri, opts)
	if err != nil {
		log.Printf("NewClient error:%v\n", err)
	 	time.Sleep(2 * time.Second)
		connect()
		return
	}
	client.On("connection", func() {
		log.Printf("on connect\n")
	})
	client.On("hello", func(msg string) {
		log.Printf("on message:%v\n", msg)
	})
	client.On("disconnection", func() {
		connect()
		log.Printf("on disconnect\n")
	})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants