If any one using agsXMPP namespace kindly tell me of how to create custom packets and send it. If there is any supporting source code pls help me. thanks in advance
Example:
We want to create our own XMPP extension to send weather information over the XMPP network. The easiest way to do that is to embed the data with a message stanza. Our raw XML message with embedded weather information will look like that:
We created a new namespace for our own protocol and the 3 new elements weather, humidity and temperature.
First we create a new class weather.cs for our custom XML-Element and derive from agsXMPP.Xml.Dom.Element
using System;
using agsXMPP.Xml.Dom;
namespace MiniClient
{
publicclass Weather : Element
{
public Weather()
{
this.TagName="weather";
this.Namespace="agsoftware:weather";
}
public Weather(int humidity, int temperature):this()
{
this.Humidity= humidity;
this.Temperature= temperature;
}
publicint Humidity
{
get {return GetTagInt("humidity");}
set { SetTag("humidity", value.ToString());}
}
publicint Temperature
{
get {return GetTagInt("temperature");}
set { SetTag("temperature", value.ToString());}
}
}
}
We have to register the new class in the ElementFactory. Without registering the class the XML-Parser is not able to build or weather objects while parsing the XML-Stream. We register the class with the following line of code:
However, when the message is received by the remote side using the following code, bWeather remains false as the query type would seem to be agsXMPP.Xml.Dom.Element and not agsXMPP.protocol.extensions.Weather.Weather:
private void XmppCon_OnIq(object sender, agsXMPP.Xml.Dom.Node e)
{
if (InvokeRequired)
{
// Windows Forms are not Thread Safe, we need to invoke this
// We're not in the UI thread, so we need to call BeginInvoke
BeginInvoke(new StreamHandler(XmppCon_OnIq), new object[] { sender, e });
return;
}
agsXMPP.protocol.client.IQ iq = e as IQ;
if (iq != null)
{
Element query = iq.Query;
if (query != null)
{
bool bWeather = false;
if (query.GetType() == typeof(agsXMPP.protocol.extensions.Weather.Weather))
bWeather = true;
}
}
}
ofcourse i have registered weather (with "query" as tagname) with the element factory.
Any idea why is it so? is it the openfire server or something else.
service-unavailable normally indicates that the entity the stanzas should be delivered to is unavailable.
Is sample@localxmppserver/agsXMPP available when you are sending the IQ?
Hi Alex
I have just written a simple client application to login using XMPPClientConnection. It handles sending/receiving messages and IQs.
So far i have tried out sending iqs addressed to server and had no problem with the same.
Just then i tried sending a custom iq (weatheriq) from 'test' user to 'sample' user by using the same simple clients - one each for the respective user.
note: I have not taken care of any presence stanza information as i'm not aware whether those are needed.
Thanks
blorecrafter
in your case Iqs get delivered from client to client. Unlike messages they are not stored for offline delivery by the server. They can be only delivered when the user is online. And the Iqs must be sent to the full Jids.
So you need the presence information to get the resources and deliver the iq to the correct full jid. Otherwise you get the error messages you posted before.