Not able to connect. What am I doing wrong?

Feb 12, 2013 at 7:50 AM
Hello,

I tried to connect in an simple example with my google talk account, but unfortunately I don't make it work. For somewhat reason I'm not able to see my error. Here's the code I wrote. Maybe somebody can give me a hint. The app always appends a message about the current state and usually it prints out:

Connecting
Connected
Authenticating
Unknown

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp1.Resources;
using System.Net.XMPP.GoogleTalk;
using System.Net.XMPP;

namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
    private XMPPClient XMPPClient;

    // Konstruktor
    public MainPage()
    {
        InitializeComponent();

     }

    private void XMPPClient_OnStateChanged(object sender, EventArgs e)
    {
        Dispatcher.BeginInvoke(delegate
        {
            text.Text += XMPPClient.XMPPState.ToString() + "\n";
        });
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        try
        {

            XMPPAccount account = new XMPPAccount();
            account.JID = "sparkitny@gmail.com/phone";
            account.Domain = "gmail.com";
            account.Server = "talk.google.com";
            account.Port = 5223; // 5222;
            account.UseOldSSLMethod = true;
            account.UseTLSMethod = true;
            account.AccountName = "xxxxxxxx@gmail.com";
            account.Password = "xxxxxxxxxxxx";
            account.Resource = Guid.NewGuid().ToString();

            Dispatcher.BeginInvoke(delegate
            {
                text.Text += string.Format("Connected {0}", account.HaveSuccessfullyConnectedAndAuthenticated);
            });

            XMPPClient = new XMPPClient();
            XMPPClient.AutomaticallyDownloadAvatars = true;
            XMPPClient.AutoQueryServerFeatures = true;
            XMPPClient.AutoReconnect = true;

            XMPPClient.XMPPAccount = account;

            XMPPClient.OnStateChanged += XMPPClient_OnStateChanged;
            XMPPClient.Connect();
        }
        catch (Exception exn)
        {
            text.Text += exn.Message + "\n";
        }
    }

    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
        text.Text = "";
    }

    private void Button_Click_3(object sender, RoutedEventArgs e)
    {
        XMPPClient.Disconnect();
    }

    private void Button_Click_4(object sender, RoutedEventArgs e)
    {
        var items = XMPPClient.RosterItems;

        foreach (var item in items)
        {
            Append(string.Format("{0} {1}", item.JID, item.Name));
        }
    }

    private void Append(string s)
    {
        Dispatcher.BeginInvoke(delegate
        {
            text.Text += s + "\n";
        });
    }
}
}
}
Feb 27, 2013 at 8:02 AM
are you able to fix this issue, I am having the same problem.
Apr 23, 2013 at 10:37 AM
Edited Apr 23, 2013 at 10:39 AM
Hello,

Unable to connect to gtalk via my Windows Phone App and with the same code able to connect to jabber.org... Dont know what i am doing wrong.

XMPPClient.Server = " talk.google.com";
XMPPClient.Domain = "gmail.com";
XMPPClient.UserName = "gtalk_UserName";
XMPPClient.Password = "gtalk_Password";
XMPPClient.UseTLS = true;
XMPPClient.UseOldStyleTLS = true;
XMPPClient.AutoAcceptPresenceSubscribe = false;
XMPPClient.AutomaticallyDownloadAvatars = false;
XMPPClient.AutoReconnect = true;
I used xmpp port as
XMPPClient.Port = 5223;
I also used 5222 and 443 port number but unable to connect.
What's wrong with this?
Please suggest me possible solutions to connect with gtalk users via my Windows Phone App.
Jun 7, 2013 at 5:41 PM
I am having the same issue.
Able to login using Jabber client.
Not able to login uisng Gtalk and getting "unknown" error.
Not able to login using Facebook and getting "authentication failed"
Aug 16, 2013 at 5:24 AM
Edited Aug 16, 2013 at 9:46 AM
Hello,
Can u please provide me some sample code to run xmpp client in windows phone
Thanks in advance...