Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Esofter #1
Member since Oct 2009 · 20 posts
Group memberships: Members
Show profile · Link to this post
Subject: Reconnect.
Hello. When the program is running, may be lost internet connection.When the connection is resumed, I re-open the connection to the server. But getting a socket error.
When starting the program connected in such a way
  1. Jid jidSender = new Jid(this.Username + "@" + this.Server);
  2. this.xmpp.Server = jidSender.Server;
  3. this.xmpp.Username = jidSender.User;
  4. this.xmpp.Password = Password;
  5. this.xmpp.UseCompression = true;
  6. this.xmpp.Resource = "plugin_mt";
  7. this.xmpp.EnableCapabilities = true;
  8. this.xmpp.ClientVersion = "1.0";
  9. this.xmpp.Capabilities.Node = "http://www.ag-software.net/miniclient/caps";
  10. this.xmpp.Open();
When connectio lost

this.xmpp.Close();

And when I again do connect

  1. Jid jidSender = new Jid(this.Username + "@" + this.Server);
  2. this.xmpp.Server = jidSender.Server;
  3. this.xmpp.Username = jidSender.User;
  4. this.xmpp.Password = Password;
  5. this.xmpp.UseCompression = true;
  6. this.xmpp.Resource = "plugin_mt";
  7. this.xmpp.EnableCapabilities = true;
  8. this.xmpp.ClientVersion = "1.0";
  9. this.xmpp.Capabilities.Node = "http://www.ag-software.net/miniclient/caps";
  10. this.xmpp.Open();

I get socket error.
What am I doing wrong?
Thank you.
This post was edited on 2013-03-06, 20:27 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You should not reconnect in the OnClose event. After OnClose there is still some internal cleanup in the library.
And when there is a network problem then in most cases the first reconnect in the OnClose event will anyway until the network is up again. I suggest to start a timer in the OnClose event and try to reconnect in the timer event handler. Stop the timer in the event handler when you try to reconnect and start it again when it fails.

In my reconnect logic I increase the timer interval when it fails until I reach 180 seconds. I have an array which the following timer intervals which words very well.

  1. private int[] reconnectInterval = {30, 60, 60, 120, 120, 300};

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS