Subject: agsXMPP
i am developing a Windows application in c# in which i am required to connect to the Openfire server via a chat client which i am tryn to develop in csharp
the code i have written uptil now is as :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.Text;
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using System.Threading;
namespace JClient
{
public partial class JClient : Form
{
static bool _wait;
static string JID_Sender;
static string password;
static Jid jidSender = new Jid(JID_Sender);
string JID_Receiver,outMessage;
XmppClientConnection xmpp = new XmppClientConnection(jidSender.Server);
public JClient()
{
InitializeComponent();
}
private void login_Click(object sender, EventArgs e)
{
JID_Sender = jid.Text;
password = pword.Text;
MessageBox.Show("The jid is:" + JID_Sender);
MessageBox.Show("The password is:" + password);
Jid jidSender = new Jid(JID_Sender);
XmppClientConnection xmpp = new XmppClientConnection(jidSender.Server);
try
{
xmpp.Open(jidSender.User, password);
xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
}
catch (Exception k)
{
MessageBox.Show(k.Message);
}
MessageBox.Show("waiting for login...1");
info.Text = "Wait for Login ";
MessageBox.Show("waiting for login...2");
int i = 0;
_wait = true;
do
{
info.Text += ".";
i++;
if (i == 10)
_wait = false;
Thread.Sleep(500);
} while (_wait);
info.Clear();
MessageBox.Show("waiting for login...3");
info.Text += "Login Status:";
info.Text += "xmpp Connection State {0}" + xmpp.XmppConnectionState;
info.Text += "xmpp Authenticated? {0}" + xmpp.Authenticated;
MessageBox.Show("waiting for login...4");
info.Clear();
// }
MessageBox.Show("before presence!");
info.Text = "Sending Precence";
Presence p = new Presence(ShowType.chat, "Online");
p.Type = PresenceType.available;
xmpp.Send(p);
MessageBox.Show("after presence!");
xmpp.OnPresence += new PresenceHandler(xmpp_OnPresence);
Thread.Sleep(500);
info.Text = "";
MessageBox.Show("Enter Chat Partner JID:");
i = 0;
_wait = true;
do
{
//info.Text += ".";
i++;
if (i == 10)
_wait = false;
Thread.Sleep(500);
} while (_wait);
//MessageBox.Show("after chat partner!");
info.Text = "";
info.Text = "Start Chat";
info.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
JID_Receiver = info.Text;
//MessageBox.Show("partners JID: " + JID_Receiver);
info.Clear();
MessageBox.Show("START CHAT!");
//goto l1;
}
static void xmpp_OnPresence(object sender, Presence pres)
{
MessageBox.Show("Available Contacts: ");
MessageBox.Show("{0}@{1} {2}" + pres.From.User + pres.From.Server + pres.Type);
//jcStatus.Text=" ";(pres.From.User + "@" + pres.From.Server + " " + pres.Type);
// jcStatus.Text=" ";();
}
// Is raised when login and authentication is finished
static void xmpp_OnLogin(object sender)
{
_wait = false;
MessageBox.Show("Logged In");
//info.Text += "Logged in";
}
//Handles incoming messages
static void MessageCallBack(object sender,
agsXMPP.protocol.client.Message msg,
object data)
{
MessageBox.Show("BUZZZZZ...");
if (msg.Body != null)
{
MessageBox.Show("WE R IN!");
// Console.ForegroundColor = ConsoleColor.Red;
//jcReceive.Text=
MessageBox.Show("{0}>> {1}" + msg.From.User + msg.Body); ////////////chk this it doesnt recognize text box name here
// Console.ForegroundColor = ConsoleColor.Green;
}
}
private void jcSend_KeyDown(object sender, KeyEventArgs e)
{
bool halt = false;
outMessage = jcSend.Text;
if (e.KeyCode == Keys.Enter)
{
xmpp.MesagageGrabber.Add(new Jid(JID_Receiver),
new BareJidComparer(),
new MessageCB(MessageCallBack),
null);
MessageBox.Show("jid of partner: " + JID_Receiver);
// bool halt = false;
//do
//{
// Console.ForegroundColor = ConsoleColor.Green;
// outMessage = jcSend.Text;
// MessageBox.Show("jcSendText: " + jcSend.Text);
if (outMessage == "q!")
{
//halt = true;
xmpp.Close();
}
else
{
xmpp.Send(new agsXMPP.protocol.client.Message(new Jid(JID_Receiver),
MessageType.chat,
outMessage));
MessageBox.Show("Message sent");
}
// } while (!halt);
}
//xmpp.Close();
}
}
}
In this while debugging control isint reaching inside the callback function. After pressing the enter key the msg is being sent but not being received by the other client
Login and authentication is working properly.
The Windows form consists of 4 text-boxes for id(jid),password(pword),input (jcSend)and output (info). I have used two buttons: 1 for login (login)and 1 for taking the partners jid from the user ( button1).
Can u plz help?
the code i have written uptil now is as :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.Text;
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using System.Threading;
namespace JClient
{
public partial class JClient : Form
{
static bool _wait;
static string JID_Sender;
static string password;
static Jid jidSender = new Jid(JID_Sender);
string JID_Receiver,outMessage;
XmppClientConnection xmpp = new XmppClientConnection(jidSender.Server);
public JClient()
{
InitializeComponent();
}
private void login_Click(object sender, EventArgs e)
{
JID_Sender = jid.Text;
password = pword.Text;
MessageBox.Show("The jid is:" + JID_Sender);
MessageBox.Show("The password is:" + password);
Jid jidSender = new Jid(JID_Sender);
XmppClientConnection xmpp = new XmppClientConnection(jidSender.Server);
try
{
xmpp.Open(jidSender.User, password);
xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
}
catch (Exception k)
{
MessageBox.Show(k.Message);
}
MessageBox.Show("waiting for login...1");
info.Text = "Wait for Login ";
MessageBox.Show("waiting for login...2");
int i = 0;
_wait = true;
do
{
info.Text += ".";
i++;
if (i == 10)
_wait = false;
Thread.Sleep(500);
} while (_wait);
info.Clear();
MessageBox.Show("waiting for login...3");
info.Text += "Login Status:";
info.Text += "xmpp Connection State {0}" + xmpp.XmppConnectionState;
info.Text += "xmpp Authenticated? {0}" + xmpp.Authenticated;
MessageBox.Show("waiting for login...4");
info.Clear();
// }
MessageBox.Show("before presence!");
info.Text = "Sending Precence";
Presence p = new Presence(ShowType.chat, "Online");
p.Type = PresenceType.available;
xmpp.Send(p);
MessageBox.Show("after presence!");
xmpp.OnPresence += new PresenceHandler(xmpp_OnPresence);
Thread.Sleep(500);
info.Text = "";
MessageBox.Show("Enter Chat Partner JID:");
i = 0;
_wait = true;
do
{
//info.Text += ".";
i++;
if (i == 10)
_wait = false;
Thread.Sleep(500);
} while (_wait);
//MessageBox.Show("after chat partner!");
info.Text = "";
info.Text = "Start Chat";
info.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
JID_Receiver = info.Text;
//MessageBox.Show("partners JID: " + JID_Receiver);
info.Clear();
MessageBox.Show("START CHAT!");
//goto l1;
}
static void xmpp_OnPresence(object sender, Presence pres)
{
MessageBox.Show("Available Contacts: ");
MessageBox.Show("{0}@{1} {2}" + pres.From.User + pres.From.Server + pres.Type);
//jcStatus.Text=" ";(pres.From.User + "@" + pres.From.Server + " " + pres.Type);
// jcStatus.Text=" ";();
}
// Is raised when login and authentication is finished
static void xmpp_OnLogin(object sender)
{
_wait = false;
MessageBox.Show("Logged In");
//info.Text += "Logged in";
}
//Handles incoming messages
static void MessageCallBack(object sender,
agsXMPP.protocol.client.Message msg,
object data)
{
MessageBox.Show("BUZZZZZ...");
if (msg.Body != null)
{
MessageBox.Show("WE R IN!");
// Console.ForegroundColor = ConsoleColor.Red;
//jcReceive.Text=
MessageBox.Show("{0}>> {1}" + msg.From.User + msg.Body); ////////////chk this it doesnt recognize text box name here
// Console.ForegroundColor = ConsoleColor.Green;
}
}
private void jcSend_KeyDown(object sender, KeyEventArgs e)
{
bool halt = false;
outMessage = jcSend.Text;
if (e.KeyCode == Keys.Enter)
{
xmpp.MesagageGrabber.Add(new Jid(JID_Receiver),
new BareJidComparer(),
new MessageCB(MessageCallBack),
null);
MessageBox.Show("jid of partner: " + JID_Receiver);
// bool halt = false;
//do
//{
// Console.ForegroundColor = ConsoleColor.Green;
// outMessage = jcSend.Text;
// MessageBox.Show("jcSendText: " + jcSend.Text);
if (outMessage == "q!")
{
//halt = true;
xmpp.Close();
}
else
{
xmpp.Send(new agsXMPP.protocol.client.Message(new Jid(JID_Receiver),
MessageType.chat,
outMessage));
MessageBox.Show("Message sent");
}
// } while (!halt);
}
//xmpp.Close();
}
}
}
In this while debugging control isint reaching inside the callback function. After pressing the enter key the msg is being sent but not being received by the other client
Login and authentication is working properly.
The Windows form consists of 4 text-boxes for id(jid),password(pword),input (jcSend)and output (info). I have used two buttons: 1 for login (login)and 1 for taking the partners jid from the user ( button1).
Can u plz help?