protected override void OnConnected(bool bSuccess, string strErrors) { try { if ((bSuccess == true) && (Client.Connected == true)) { this.Client.NoDelay = true; #if !WINDOWS_PHONE this.Client.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, Windows.Networking.Sockets.SocketOptionName.KeepAlive, true); #endif #if WINDOWS_PHONE var cancellationTokenSource = new System.Threading.CancellationTokenSource(); var task = Repeat.Interval( TimeSpan.FromSeconds(60), () => OnKeepAlive(), cancellationTokenSource.Token ); // this.Client.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, Windows.Networking.Sockets.SocketOptionName.KeepAlive, true); #endif XMPPClient.XMPPState = XMPPState.Connected; XMPPClient.FireConnectAttemptFinished(true); System.Diagnostics.Debug.WriteLine(string.Format("Successful TCP connection")); } else { XMPPClient.XMPPState = XMPPState.Unknown; XMPPClient.FireConnectAttemptFinished(false); System.Diagnostics.Debug.WriteLine(string.Format("Failed to connect: {0}", strErrors)); return; } if (XMPPClient.UseOldStyleTLS == true) { StartTLS(); } /// Send stream header if we haven't yet XMPPClient.XMPPState = XMPPState.Authenticating; OpenStreamStanza open = new OpenStreamStanza(this.XMPPClient); string strSend = open.XML; byte[] bStanza = System.Text.UTF8Encoding.UTF8.GetBytes(strSend); this.Send(bStanza); } catch (TimeoutException tx) { Console.WriteLine(tx.InnerException.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }