20
Answers

XMPP

atul chauhan

atul chauhan

10y
1.7k
1
I build the xmpp demo for windows phone 8.1 and login successfuly send message succuessfully but in case of retreiving the message i failed anybody pls help me. i think this code will help.. obj_xmpp.xmpp_client.OnXMLReceived += new System.Net.XMPP.XMPPClient.DelegateString(XMPPClient_OnXMLReceived);
 
Answers (20)
1
Karthik Kumar
NA 182 23.1k 9y
hi nice and helpfull article.I created another window for sending messages(above my code) here only one page in your article.using singleton how can i maintain the server connection in the next page also? i tried in the above code but cant get..
1
Suresh M
NA 18.6k 1.5m 9y
http://www.c-sharpcorner.com/UploadFile/2b876a/implementing-extensible-messaging-and-presence-protocol-xmp/
1
Suresh M
NA 18.6k 1.5m 9y
create separate  singleton class file and call from there.
1
Suresh M
NA 18.6k 1.5m 9y
if you use singleton class then you can send message at any screen and use Binding and 
INotifyPropertyChanged Interface class to show the  message in any screen.
 
Please make it as correct answer if it helps you!!!!!! 
1
Karthik Kumar
NA 182 23.1k 9y
yup thanx.letme try singleton pattern.i have to send message in second page and that message should display in the screen.what i can do?
1
Suresh M
NA 18.6k 1.5m 9y

Attachment wp8xmpp_t.zip

Hi i checked your code.Problem is you are not maintain the xmpp connection properly .If you need the xmpp connection in different screen ,then you need to implement the singleton class.
 
now run the app and send the message in the same screen.
 
For testing
  
Install gajim  and login with one user account(user1)
 
Now run your WPH app and login  with another user(user2)
 
after successful login in WPH  enter your To JID and send the message.
 
----------------------------------------------------------------
This XMPP library doesn't support MUC(group chat) protocol. You need to rewrite the xmpp library.
1
Suresh M
NA 18.6k 1.5m 9y
install Gajim client for testing
 http://gajim.org/downloads.php?lang=en
 
Send your sample project i will check and help you 
 
 
 
1
Suresh M
NA 18.6k 1.5m 10y
can you send .what xmpp library you used .
0
Suresh M
NA 18.6k 1.5m 9y
xmpp media net its also available in C# corner downloads 
0
Asfend Yar
NA 3.9k 226.6k 9y
Which library you are using ?
0
Karthik Kumar
NA 182 23.1k 9y

hi, good day! I have some general doubts regarding xmpp-openfire-chat app please clear me..

1. Now i am able to send message to the server. I want to send and receive messages from another devices.For that what i have to do?

2.In my UI i want to receive messages from Gajin .It should be like Gajin receive from my end.I have sqlite is here,

a.First i have to create a table for receiving messages from server?

b.from that table i have to bind using I notify property?3.to show messages like gajin in my UI what i have to do?

please clarify these doubts...

0
Karthik Kumar
NA 182 23.1k 9y
hi you got? i didnt
0
Karthik Kumar
NA 182 23.1k 9y

Attachment wp8xmpp.rar

hai i tried singleton thred safe methode.but idontknow how to impliment please see my code and help i attached rar also
 
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 MainPage()
{
InitializeComponent();
}
private static volatile Singleton instance;
private static object syncRoot = new Object();
public static XMPPConnection ObjXmppCon;
public static XMPPClient ObjXmppClient;
public static Boolean IsXmppSuccess { get; set; }
public String UserName { get; set; }
public String PassWord { get; set; }
public readonly String Server = "taurus";
public readonly String ServerIPAddress = "127.0.0.1:9090";
public sealed class Singleton
{
private Singleton() { }
public static Singleton Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new Singleton();
}
}
return instance;
}
}
}
public 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();
//initializing the xmpp connection
ObjXmppCon.OnAsyncConnectFinished += ObjXmppCon_OnAsyncConnectFinished;
ObjXmppClient.OnStateChanged += new EventHandler(XMPPClient_OnStateChanged);
Thread.Sleep(2000);
}
public void ObjXmppCon_OnAsyncConnectFinished(xmedianet.socketserver.SocketClient client, bool bSuccess, string strErrors)
{
IsXmppSuccess = client.Connected;
}
public void XMPPClient_OnStateChanged(object sender, EventArgs e)
{
switch (ObjXmppClient.XMPPState)
{
case XMPPState.Ready:
if (IsXmppSuccess)// the name isxmpp does not contain in the current context
{
this.Dispatcher.BeginInvoke(() =>
{
NavigationService.Navigate((new Uri("/Output.xaml?key=success", UriKind.Relative)));//error
});
}
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;
}
}
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();
}
}
}
 
0
Karthik Kumar
NA 182 23.1k 9y
hi pleas do the needfull
0
Karthik Kumar
NA 182 23.1k 9y

Attachment wp8xmpp.rar

hi  when i am trying to create connection  using singleton class my methods showing error. XMPPClient_OnStateChanged,txtUserName,pw everything showeing error.i cant fix pleese help me what happend. pls find my attached .rar
 
 
 
 
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
{
/// <summary>
/// Username of the client
/// </summary>
public String UserName { get; set; }
/// <summary>
/// Password
/// </summary>
public String PassWord { get; set; }
private Boolean IsXmppSuccess { get; set; }
private readonly String Server = "taurus";
private readonly String ServerIPAddress = "127.0.0.1:9090";//127.0.0.1:9090/
/// <summary>
/// Xmpp Client
/// </summary>
/// <summary>
/// XMPP Connection
/// </summary>
public XMPPConnection ObjXmppCon { get; set; }
// Constructor
public MainPage()
{
InitializeComponent();
}
private static XMPPClient ObjXmppClient ;
public class singleton
{
private static singleton instance;
private static XMPPConnection ObjXmppCon;
public String UserName { get; set; }
public String PassWord { get; set; }
private Boolean IsXmppSuccess { get; set; }
private readonly String Server = "taurus";
private readonly String ServerIPAddress = "127.0.0.1:9090";//127.0.0.1:9090/
private singleton()
{
}
public static singleton GetInstance()
{
if (instance== null)
{
instance = new singleton();
}
return instance;
}
public void IsXmppValid(string UserName,string PassWord )
{
ObjXmppClient = new XMPPClient();
ObjXmppClient.JID = UserName + "@" + Server;
ObjXmppClient.Password = PassWord;
ObjXmppClient.Server = ServerIPAddress; //user server for emulator and ip address for device.
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();
//initializing the xmpp connection
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;
}
public static void XMPPClient_OnStateChanged(object sender, EventArgs e)//error
{
switch (ObjXmppClient.XMPPState)
{
case XMPPState.Ready:
if (IsXmppSucces)
{
this.Dispatcher.BeginInvoke(() =>
{
//CloseOverLay();
//MessageBox.Show("Successfully logged in");
NavigationService.Navigate((new Uri("/Output.xaml?key=success", UriKind.Relative)));
//return;
});
}
else
{
this.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Check server name/IpAddress");
//NavigationService.Navigate((new Uri("/Output.xaml?key=failed", UriKind.Relative)));,knhjslkil
return;
});
}
break;
case XMPPState.AuthenticationFailed: this.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Enter valid username and password");
//NavigationService.Navigate((new Uri("/Output.xaml?key=wrong", UriKind.Relative)));
return;
}); break;
}
}
private void btnLogin_Click(object sender, RoutedEventArgs e)//error
{
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();//error
PassWord = txtPassword.Password.Trim();
IsXmppValid();
}
}
}
}
 
0
Karthik Kumar
NA 182 23.1k 9y

Attachment wp8xmpp.rar

i send the project,please help me how to create group chat and all
0
Karthik Kumar
NA 182 23.1k 9y
hai me too trying to send and receive messages.i successfully logged into the server but i cant send n receive messages.can you share the code please?
0
Karthik Kumar
NA 182 23.1k 9y
i successfully logged into the server but now i cant send and receive the messages,even i dont know my code is write or wrong..please tell mehow to csend and receive and how to check in the openfire weather message is received or not? how can i test my app with 2 emulators?
 
here is my code to send messages..
 
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 = "smitha";
public String PassWord= "smitha" ;
private Boolean IsXmppSuccess { get; set; }
private readonly String Server = "taurus";
private readonly String ServerIPAddress = "127.0.0.1:9090";//127.0.0.1:9090/
XMPPClient ObjXmppClient = new XMPPClient();
JID jidto = new JID("smitha@taurus");
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"))
{
// lblShowResult.Text = "Successfully Logged in";
}
}
}
private void SendXmppMessage(String Message, JID ReceiverJid)
{
try
{
ObjXmppClient.JID = UserName + "@" + Server;
ObjXmppClient.Password = PassWord;
ObjXmppClient.Server = ServerIPAddress; //user server for emulator and ip address for device.
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);
}
catch(Exception ex)
{
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
SendXmppMessage(txttype.Text, jidto);
}
}
}
 
0
Suresh M
NA 18.6k 1.5m 9y
what help you need .?
0
Karthik Kumar
NA 182 23.1k 9y
hai can you help me suresh,