go-xmpp
go-xmpp copied to clipboard
Is there a way to check if connection is still alive?
First thank you for this library and the echo bot example. I was able to build a simple bot without programming experience following the example, although I have to admit at the start I used code from this repo.
But despite reading in the library a lot it is still not clear to me how I could check whether the connection is still alive. My bot works pretty well till it stops working due to a network flaw/reconnect. Could you please give me a hint at which modules/functions I should have a closer look?
Client-to-Server Pings may help you.
https://xmpp.org/extensions/xep-0199.html#c2s
thx, I'll try to implement a ping if there was no activity since ~5 minutes.
Ping is a bit heavy on the server. Some servers (like ejabberd on SaaS) support whitespace ping. I will try to add this method (whitespace ping) when I have some time to work on go-xmpp.
@mdosch Sorry it took so long, but I am finally working on the disconnect detection and adding some way to trigger reconnect.
@mdosch I think the new ClientManager should do what you need. It reconnects automatically when the connection is lost. You can check how to use it in the xmpp_echo example: https://github.com/FluuxIO/go-xmpp/blob/master/cmd/xmpp_echo/xmpp_echo.go
I guess we can close this ticket now. You can also monitor progress on connection loss detection that will add an active way to detect connection loss: #35
Thank you, I will check it out. :)
Although I am using the StreamManager as in your echo bot example, see here it seems to still not work properly. Whenever I restart my prosody the bot seems to not reconnect as it doesn't reply anymore. Do I need to configure more than shown in the echo bot example?
This is the output from one of my bots in journalctl:
Jul 04 12:39:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:23 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>
Jul 04 12:39:38 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:38 NextStart read tcp 127.0.0.1:39290->127.0.0.1:5222: use of closed network connection
Jul 04 12:39:53 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:53 NextStart read tcp 127.0.0.1:39324->127.0.0.1:5222: read: connection reset by peer
Jul 04 12:39:53 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:53 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>
Jul 04 12:40:08 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:08 stream error: system-shutdown
Jul 04 12:40:08 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:08 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>
Jul 04 12:40:08 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:08 NextStart read tcp 127.0.0.1:39414->127.0.0.1:5222: use of closed network connection
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 NextStart read tcp 127.0.0.1:39516->127.0.0.1:5222: use of closed network connection
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 NextStart read tcp 127.0.0.1:39520->127.0.0.1:5222: use of closed network connection
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>