How to connect to server though XMPP library in windows phone 8

May 21, 2014 at 8:35 AM
Edited Jun 13, 2014 at 1:34 PM
How to connect to server though XMPP library in windows phone 8,but i had written the below code to connect but iam not able to connect it.please let me know the issue

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 System.Runtime.Serialization;
using System.Net.XMPP;

namespace XMPPClient
{
public partial class Page1 : PhoneApplicationPage
{

    List<XMPPAccount> Accounts = new List<XMPPAccount>();
    public Page1()
    {
        InitializeComponent();

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

        try
        {
            XMPPAccount XMPPAccount = new XMPPAccount();


            XMPPAccount.JID = "test2@**********/phone";
            XMPPAccount.Domain = "**********";
            XMPPAccount.Server = "*********";
            XMPPAccount.Port = 5222;
            XMPPAccount.UseOldSSLMethod = true;
            XMPPAccount.UseTLSMethod = true;
            XMPPAccount.AccountName = "New Account";
            XMPPAccount.Password = "123456";
            XMPPAccount.Resource = Guid.NewGuid().ToString();


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







            App.XMPPClient.AutomaticallyDownloadAvatars = true;
            App.XMPPClient.AutoQueryServerFeatures = true;
            App.XMPPClient.AutoReconnect = true;

            App.XMPPClient.XMPPAccount = XMPPAccount;

            App.XMPPClient.OnStateChanged += XMPPClient_OnStateChanged;
            App.XMPPClient.Connect();

            //NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); 
        }
        catch (Exception exn)
        {
            text.Text += exn.Message + "\n";
        }
        //Accounts.Add(XMPPAccount);
        //List<XMPPAccount> NewAccounts = new List<XMPPAccount>();
        //NewAccounts.AddRange(Accounts);

        //App.XMPPClient.XMPPAccount.Password = txtpwd.Text.ToString();
        //App.XMPPClient.Connect(App.Current as xmedianet.socketserver.ILogInterface);
        //System.Diagnostics.Debug.WriteLine(App.XMPPClient.XMPPConnection);
        //NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); 
    }

    private void btnclik4(object sender, RoutedEventArgs e)
    {
        var items = App.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";
        });
    }
}
}