Here is a simple tutorial to connect to nimbuzz and send message.
Requirements:
Lets start!!
Firstly open Microsoft Visual C++ 2010 Express and Select New Project
Now you can see window like above picture. Select Windows Form Application and name it MyFirstApp , Then click OK
After the project is created, The next step is to add a reference to agsXMPP.dll which we have downloaded earlier (Take a look at picture below)
Select Browse and open agsXMPP.dll
And your form should look like the following,You can add more fields in form, My form is short because i want to make you understand easily.
Now Press F7 and select all code and replace it with the code below
Code :-
Now we have all done .Press F5 to start debug the appli. Enjoyyy
Feeling lazy? No probs Download project file from here
Please feel free to ask any question below.
Requirements:
- Microsoft Visual Basic 2010
- agsXMPP.dll ( Can be downloaded from here or check the attachments below)
Lets start!!
Firstly open Microsoft Visual C++ 2010 Express and Select New Project
Now you can see window like above picture. Select Windows Form Application and name it MyFirstApp , Then click OK
After the project is created, The next step is to add a reference to agsXMPP.dll which we have downloaded earlier (Take a look at picture below)
Select Browse and open agsXMPP.dll
And your form should look like the following,You can add more fields in form, My form is short because i want to make you understand easily.
Now Press F7 and select all code and replace it with the code below
Code :-
- Code:
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 agsXMPP;
using agsXMPP.protocol.client;
namespace MyFirstApp
{
public partial class Form1 : Form
{
XmppClientConnection gFgCon = new XmppClientConnection();
public Form1()
{
InitializeComponent();
button1.Click += new System.EventHandler(button1_Click);
button2.Click += new System.EventHandler(button2_Click);
Load += new System.EventHandler(Form1_Load);
listBox1.SelectedIndexChanged += new System.EventHandler(listBox1_SelectedIndexChanged);
button3.Click += new System.EventHandler(button3_Click);
gFgCon.OnLogin += new ObjectHandler(gFgCon_onlogin);
gFgCon.OnAuthError += new XmppElementHandler(gFgCon_onAuthEror);
gFgCon.OnPresence += new agsXMPP.protocol.client.PresenceHandler(connection_onpresence);
gFgCon.OnMessage += new agsXMPP.protocol.client.MessageHandler(connection_onmsg);
}
void gFgCon_onAuthEror(object sender, agsXMPP.Xml.Dom.Element e)
{
if (InvokeRequired)
{
BeginInvoke(new XmppElementHandler(gFgCon_onAuthEror), new object[] { sender, e });
return;
}
MessageBox.Show("Wrong username or password", "Error");
button1.Enabled = true; button2.Enabled = false;
}
void gFgCon_onlogin(object sender)
{
if (InvokeRequired)
{
BeginInvoke(new ObjectHandler(gFgCon_onlogin), new object[] { sender });
return;
}
MessageBox.Show("Login success","Connected");
button1.Enabled = false;
button2.Enabled = true;
gFgCon.Status = "Hi there!"; //Set Status here
gFgCon.Show = agsXMPP.protocol.client.ShowType.NONE; //Set Status type
gFgCon.SendMyPresence();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty || textBox2.Text == string.Empty)
{
MessageBox.Show("Invalid username or password", "Error");
}
else
{
button1.Enabled = false;
gFgCon.Server = "nimbuzz.com";
gFgCon.Username = textBox1.Text;
gFgCon.Password = textBox2.Text;
gFgCon.Resource = "_gFg"; // You can change resource here
gFgCon.Priority = 10;
gFgCon.Port = 5222;
gFgCon.AutoAgents = false;
gFgCon.AutoResolveConnectServer = true;
gFgCon.UseCompression = false;
gFgCon.Open();
//--------
}
}
void connection_onpresence(object sender, agsXMPP.protocol.client.Presence pres)
{
if (InvokeRequired)
{
BeginInvoke(new agsXMPP.protocol.client.PresenceHandler(connection_onpresence), new object[] { sender, pres });
return;
}
if (pres.Type == PresenceType.available)
{
listBox1.Items.Add(pres.From.User);
}
if (pres.Type == PresenceType.unavailable)
{
listBox1.Items.Remove(pres.From.User);
}
}
void connection_onmsg(object sender, agsXMPP.protocol.client.Message msg)
{
if (msg.Type == MessageType.error || msg.Body == null)
return;
if (InvokeRequired)
{
BeginInvoke(new agsXMPP.protocol.client.MessageHandler(connection_onmsg), new object[] { sender, msg });
return;
}
richTextBox1.SelectionColor = Color.Red;
richTextBox1.AppendText(msg.From.User+ " : ");
richTextBox1.AppendText(msg.Body);
richTextBox1.AppendText("\r\n");
textBox4.Text = msg.From.User; // id of last messaged user should b stored here
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Enabled = true;
button2.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
gFgCon.Close();
button1.Enabled = true; button2.Enabled = false;
}
private void button3_Click(object sender, EventArgs e)
{
agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message
{
To = new agsXMPP.Jid(textBox4.Text + "@nimbuzz.com"),
// for private chat in chatroom : To = new agsXMPP.Jid("chatroom@conference.nimbuzz.com/id")
Body = textBox3.Text,
Subject = "gFg",
Type = agsXMPP.protocol.client.MessageType.chat
};
gFgCon.Send(msg);
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.AppendText(textBox1.Text + " : ");
richTextBox1.AppendText(textBox3.Text);
richTextBox1.AppendText("\r\n");
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox4.Text = listBox1.SelectedItem.ToString();
}
}
}
Now we have all done .Press F5 to start debug the appli. Enjoyyy
Feeling lazy? No probs Download project file from here
Please feel free to ask any question below.