iam trying to develop an app in WP8.1 using xmpp and openfire server.i logged into the server but the message is cannot sending to the server .I successfully logged into the server.if it is not the way to send and receive please give me a sample..or please help me..iam fedup with this.
how can i check/test this with 2 emulator?
how can i see the send and receive messages?
THIS IS MY FIRST PAGE CODE ie:VALIDATING XMPP USING CREDENTIAL
Through this first page code i can log in to the openfire server
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 WP8Xmpp.Resources;
using System.Net.XMPP;
using System.Threading;
namespace WP8Xmpp
{
public partial class MainPage : PhoneApplicationPage
{
public String UserName { get; set; }
public String PassWord { get; set; }
private Boolean IsXmppSuccess { get; set; }
private readonly String Server = "server";
private readonly String ServerIPAddress = "127.0.0.1:9090";
public XMPPClient ObjXmppClient { get; set; }
public XMPPConnection ObjXmppCon { get; set; }
public MainPage()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (txtUserName.Text.Trim() == string.Empty)
{
MessageBox.Show("Enter Username");
return;
}
if (txtPassword.Password.Trim() == string.Empty)
{
MessageBox.Show("Enter Password");
return;
}
UserName = txtUserName.Text.Trim();
PassWord = txtPassword.Password.Trim();
IsXmppValid();
}
private void IsXmppValid()
{
ObjXmppClient = new XMPPClient();
ObjXmppClient.JID = UserName + "@" + Server;
ObjXmppClient.Password = PassWord;
ObjXmppClient.Server = ServerIPAddress;
ObjXmppClient.AutoReconnect = true;
ObjXmppClient.RetrieveRoster = true;
ObjXmppClient.PresenceStatus = new PresenceStatus() { PresenceType = PresenceType.available, IsOnline = true };
ObjXmppClient.AutoAcceptPresenceSubscribe = true;
ObjXmppClient.AttemptReconnectOnBadPing = true;
ObjXmppCon = new XMPPConnection(ObjXmppClient);
ObjXmppCon.Connect();
ObjXmppClient.Connect();
ObjXmppCon.OnAsyncConnectFinished += ObjXmppCon_OnAsyncConnectFinished;
ObjXmppClient.OnStateChanged += new EventHandler(xMPPClient_OnStateChanged);
Thread.Sleep(2000);
}
void ObjXmppCon_OnAsyncConnectFinished(xmedianet.socketserver.SocketClient client, bool bSuccess, string strErrors)
{
IsXmppSuccess = client.Connected;
}
void xMPPClient_OnStateChanged(object sender, EventArgs e)
{
switch (ObjXmppClient.XMPPState)
{
case XMPPState.Ready:
if (IsXmppSuccess)
{
this.Dispatcher.BeginInvoke(() =>
{
NavigationService.Navigate((new Uri("/Output.xaml?key=success",UriKind.Relative)));
});
}
else
{
this.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Check server name/IpAddress");
return;
});
}
break;
case XMPPState.AuthenticationFailed: this.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Enter valid username and password");
return;
}); break;
}
}
}
}
this is my second page code,in this page i given the code to send and receive the message,.message cannot send to the server.please help me? i cant fix the problem
my code:
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.Net.XMPP;
namespace WP8Xmpp
{
public partial class Output : PhoneApplicationPage
{
public Output()
{
InitializeComponent();
}
public String UserName = "user2";
public String PassWord= "test" ;
private Boolean IsXmppSuccess { get; set; }
private readonly String Server = "server";
private readonly String ServerIPAddress = "127.0.0.1:9090";
XMPPClient ObjXmppClient = new XMPPClient();
JID jidto = new JID("user2@server");
bool bReceived = true;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("key"))
{
string val = NavigationContext.QueryString["key"];
if (val.Contains("success"))
{
}
}
}
private void SendXmppMessage(String Message, JID ReceiverJid)
{
try
{
ObjXmppClient.JID = UserName + "@" + Server;
ObjXmppClient.Password = PassWord;
ObjXmppClient.Server = ServerIPAddress;
ObjXmppClient.AutoReconnect = true;
ObjXmppClient.RetrieveRoster = true;
ObjXmppClient.PresenceStatus = new PresenceStatus() { PresenceType = PresenceType.available, IsOnline = true };
ObjXmppClient.AutoAcceptPresenceSubscribe = true;
ObjXmppClient.AttemptReconnectOnBadPing = true;
XMPPConnection ObjXmppCon = new XMPPConnection(ObjXmppClient);
ObjXmppCon.Connect();
ObjXmppClient.Connect();
ObjXmppClient.SendChatMessage(Message.Trim(), ReceiverJid);
ObjXmppClient.OnNewConversationItem += ObjXmppClient_OnNewConversationItem;
}
catch(Exception ex)
{
}
}
void ObjXmppClient_OnNewConversationItem(RosterItem item, bool bReceived, TextMessage msg)
{
if (bReceived)
{
MessageBox.Show("sent");
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
SendXmppMessage(txttype.Text, jidto);
}
}
}