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

How to make socket is always connected? #32

Open
Ewg777 opened this issue Nov 11, 2021 · 3 comments
Open

How to make socket is always connected? #32

Ewg777 opened this issue Nov 11, 2021 · 3 comments

Comments

@Ewg777
Copy link

Ewg777 commented Nov 11, 2021

Hey @danielrbrowne!
Thanks for a great lib! How to make it always connected to the websocket? Os there any autoreconnection feature?

@Ewg777 Ewg777 changed the title Always connected How to make NWWS always connected? Nov 11, 2021
@Ewg777 Ewg777 changed the title How to make NWWS always connected? How to make NWWS is always connected? Nov 11, 2021
@Ewg777 Ewg777 changed the title How to make NWWS is always connected? How to make socket is always connected? Nov 11, 2021
@benjamin-tang-pusher
Copy link
Contributor

benjamin-tang-pusher commented Nov 18, 2021

Hi, you can use the .ping() method (https://github.com/pusher/NWWebSocket#ping-and-pong) to tell the server that the connection should be maintained. The WebSocketConnectionDelegate protocol has the func webSocketDidReceivePong(connection: WebSocketConnection) so you can handle the pong response from the server. If this fails then you could try reconnecting.

There's also the func webSocketDidDisconnect, where you can try reconnecting here as well: https://github.com/pusher/NWWebSocket#receiving-messages-and-connection-updates

I don't think there's a specific auto-reconnection feature.

@Ewg777
Copy link
Author

Ewg777 commented Nov 20, 2021

I do use the ping method and the connect after webSocketDidDisconnect, but there are many network errors that blocks the next connect. That's why I questioned here @benjamin-tang-pusher

@benjamin-tang-pusher
Copy link
Contributor

What are the network errors you are receiving? Could you paste them here?

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