Hi pavenc,
I am new in agsXMPP too but i am working with the library and i have some code that may be useful for you, this is a really *really* simple client.
using System;
using System.Drawing;
using System.Windows.Forms;
using agsXMPP;
using agsXMPP.protocol;
using agsXMPP.protocol.iq;
using agsXMPP.protocol.iq.roster;
using agsXMPP.protocol.iq.agent;
using agsXMPP.Xml.DomParser;
using System.Threading;
namespace jabberin
{
/// <summary>
/// Really Simple Jabber Client
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblServer;
private System.Windows.Forms.TextBox txtPass;
private System.Windows.Forms.Label txtMsg;
private System.Windows.Forms.Button btnSend;
private System.Windows.Forms.GroupBox gbxXMPP;
private System.Windows.Forms.TextBox txtDebug;
private System.Windows.Forms.Label lblUser;
private System.Windows.Forms.TextBox txtServer;
private System.Windows.Forms.TextBox txtUser;
private System.Windows.Forms.TextBox txtSend;
private System.Windows.Forms.Label lblPass;
private System.Windows.Forms.Button btnConnect;
private System.Windows.Forms.Button btnDisconnect;
private XmppClientConnection jClient; // Jabber Client Decalration
public MainForm()
{
InitializeComponent();
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
void BtnConnectClick(object sender, System.EventArgs e)
{
jClient = new XmppClientConnection(); // Jabber Client Instance
/**
* Events for agsXMPP library
* */
jClient.OnReadXml += new agsXMPP.XmppClientConnection.XmlHandler(jClient_OnReadXml);
jClient.OnWriteXml += new agsXMPP.XmppClientConnection.XmlHandler(jClient_OnWriteXml);
jClient.OnLogin += new ObjectHandler(jClient_OnLogin);
jClient.OnMessage += new agsXMPP.XmppClientConnection.MessageHandler(jClient_OnMessage);
jClient.OnError += new agsXMPP.XmppClientConnection.ErrorHandler(jClient_OnError);
jClient.Server = txtServer.Text;
jClient.Username = txtUser.Text;
jClient.Password = txtPass.Text;
jClient.Port = 5222;
jClient.Resource = "jabberin";
jClient.Priority = 5;
jClient.Status = "Online";
jClient.Show = ShowType.NONE;
try
{
jClient.Open();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void BtnSendClick(object sender, System.EventArgs e)
{
jClient.Send(new agsXMPP.protocol.Message("someJabberIdHere", agsXMPP.protocol.MessageType.chat, txtSend.Text));
}
void BtnDisconnectClick(object sender, System.EventArgs e)
{
try
{
jClient.Close();
gbxXMPP.Enabled = false;
}
catch
{
Application.Exit();
}
}
private void jClient_OnLogin(object sender)
{
txtDebug.Text += "we are logged in to the server now" + System.Environment.NewLine;
txtDebug.Text += "set presence" + System.Environment.NewLine;
txtDebug.SelectionStart = txtDebug.Text.Length;
txtDebug.ScrollToCaret();
jClient.SendMyPresence();
gbxXMPP.Enabled = true;
}
private void jClient_OnError(object sender, Exception ex)
{
MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
}
private void jClient_OnReadXml(object sender, string xml)
{
txtDebug.Text += "RECV XML: " + xml + System.Environment.NewLine;
txtDebug.SelectionStart = txtDebug.Text.Length;
txtDebug.ScrollToCaret();
}
private void jClient_OnWriteXml(object sender, string xml)
{
txtDebug.Text += "SEND XML: " + xml + System.Environment.NewLine;
txtDebug.SelectionStart = txtDebug.Text.Length;
txtDebug.ScrollToCaret();
}
private void jClient_OnMessage(object sender, agsXMPP.protocol.Message msg)
{
MessageBox.Show(msg.Body,"Message",MessageBoxButtons.OK,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.btnDisconnect = new System.Windows.Forms.Button();
this.btnConnect = new System.Windows.Forms.Button();
this.lblPass = new System.Windows.Forms.Label();
this.txtSend = new System.Windows.Forms.TextBox();
this.txtUser = new System.Windows.Forms.TextBox();
this.txtServer = new System.Windows.Forms.TextBox();
this.lblUser = new System.Windows.Forms.Label();
this.txtDebug = new System.Windows.Forms.TextBox();
this.gbxXMPP = new System.Windows.Forms.GroupBox();
this.btnSend = new System.Windows.Forms.Button();
this.txtMsg = new System.Windows.Forms.Label();
this.txtPass = new System.Windows.Forms.TextBox();
this.lblServer = new System.Windows.Forms.Label();
this.gbxXMPP.SuspendLayout();
this.SuspendLayout();
//
// btnDisconnect
//
this.btnDisconnect.Location = new System.Drawing.Point(104, 72);
this.btnDisconnect.Name = "btnDisconnect";
this.btnDisconnect.TabIndex = 9;
this.btnDisconnect.Text = "Disconnect";
this.btnDisconnect.Click += new System.EventHandler(this.BtnDisconnectClick);
//
// btnConnect
//
this.btnConnect.Location = new System.Drawing.Point(16, 72);
this.btnConnect.Name = "btnConnect";
this.btnConnect.TabIndex = 8;
this.btnConnect.Text = "Connect";
this.btnConnect.Click += new System.EventHandler(this.BtnConnectClick);
//
// lblPass
//
this.lblPass.AutoSize = true;
this.lblPass.Location = new System.Drawing.Point(8, 32);
this.lblPass.Name = "lblPass";
this.lblPass.Size = new System.Drawing.Size(33, 16);
this.lblPass.TabIndex = 3;
this.lblPass.Text = "Pass:";
//
// txtSend
//
this.txtSend.Location = new System.Drawing.Point(50, 32);
this.txtSend.Name = "txtSend";
this.txtSend.Size = new System.Drawing.Size(150, 20);
this.txtSend.TabIndex = 0;
this.txtSend.Text = "";
//
// txtUser
//
this.txtUser.Location = new System.Drawing.Point(48, 8);
this.txtUser.Name = "txtUser";
this.txtUser.Size = new System.Drawing.Size(104, 20);
this.txtUser.TabIndex = 0;
this.txtUser.Text = "";
//
// txtServer
//
this.txtServer.Location = new System.Drawing.Point(184, 29);
this.txtServer.Name = "txtServer";
this.txtServer.TabIndex = 7;
this.txtServer.Text = "";
//
// lblUser
//
this.lblUser.AutoSize = true;
this.lblUser.Location = new System.Drawing.Point(8, 8);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(31, 16);
this.lblUser.TabIndex = 2;
this.lblUser.Text = "User:";
//
// txtDebug
//
this.txtDebug.Location = new System.Drawing.Point(16, 64);
this.txtDebug.Multiline = true;
this.txtDebug.Name = "txtDebug";
this.txtDebug.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtDebug.Size = new System.Drawing.Size(248, 88);
this.txtDebug.TabIndex = 2;
this.txtDebug.Text = "";
//
// gbxXMPP
//
this.gbxXMPP.Controls.Add(this.txtMsg);
this.gbxXMPP.Controls.Add(this.txtDebug);
this.gbxXMPP.Controls.Add(this.btnSend);
this.gbxXMPP.Controls.Add(this.txtSend);
this.gbxXMPP.Enabled = false;
this.gbxXMPP.Location = new System.Drawing.Point(8, 104);
this.gbxXMPP.Name = "gbxXMPP";
this.gbxXMPP.Size = new System.Drawing.Size(280, 160);
this.gbxXMPP.TabIndex = 10;
this.gbxXMPP.TabStop = false;
this.gbxXMPP.Text = "XMPP";
//
// btnSend
//
this.btnSend.Location = new System.Drawing.Point(208, 32);
this.btnSend.Name = "btnSend";
this.btnSend.Size = new System.Drawing.Size(56, 23);
this.btnSend.TabIndex = 1;
this.btnSend.Text = "Send";
this.btnSend.Click += new System.EventHandler(this.BtnSendClick);
//
// txtMsg
//
this.txtMsg.AutoSize = true;
this.txtMsg.Location = new System.Drawing.Point(16, 34);
this.txtMsg.Name = "txtMsg";
this.txtMsg.Size = new System.Drawing.Size(29, 16);
this.txtMsg.TabIndex = 3;
this.txtMsg.Text = "Msg:";
//
// txtPass
//
this.txtPass.Location = new System.Drawing.Point(48, 32);
this.txtPass.Name = "txtPass";
this.txtPass.PasswordChar = '*';
this.txtPass.Size = new System.Drawing.Size(104, 20);
this.txtPass.TabIndex = 1;
this.txtPass.Text = "";
//
// lblServer
//
this.lblServer.AutoSize = true;
this.lblServer.Location = new System.Drawing.Point(160, 8);
this.lblServer.Name = "lblServer";
this.lblServer.Size = new System.Drawing.Size(41, 16);
this.lblServer.TabIndex = 6;
this.lblServer.Text = "Server:";
//
// fmrMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.gbxXMPP);
this.Controls.Add(this.btnDisconnect);
this.Controls.Add(this.btnConnect);
this.Controls.Add(this.lblServer);
this.Controls.Add(this.txtServer);
this.Controls.Add(this.lblPass);
this.Controls.Add(this.lblUser);
this.Controls.Add(this.txtPass);
this.Controls.Add(this.txtUser);
this.Name = "fmrMain";
this.Text = "Jabberin";
this.gbxXMPP.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
}
}