3
votes

I'm having problems trying to send an XMPP message to a 'Room' in our OpenFire instance. The end result is for our CruiseControl.NET build server to be able to send success/failure messages to the appropriate 'Rooms' as an additional means of notification.

I'm using the Matrix XMPP library to create a Console Application in C# using VS2010. The idea was to create a simple .exe that I can wire up to CCNet and pass a few arguments into as required.

The code below is basically the sample code from the Matrix site/documentation which I have updated to point to a room.

static void Main(string[] args)
{
    var xmppClient = new XmppClient
    {
        XmppDomain = "SERVER",
        Username = "davidc",
        Password = "*********"
    };

    xmppClient.OnRosterEnd += delegate
    {
        xmppClient.Send(new Message
        {
            To = "[email protected]",
            From = "davidc@SERVER",
            Type = MessageType.groupchat,
            Body = "Just Testing the XMPP SDK"
        });
    };
    xmppClient.Open();

    Console.WriteLine("Press return key to exit the application");
    Console.ReadLine();

    xmppClient.Close();
}

I can send to an individual user (changing the To and Type accordingly) without any problems but changing the code to point to a room ends in silence! Is there some additional 'handshaking' that needs to be done to address a room?

I don't really have to use C# for the solution as long as it will run on a Windows Server.

1

1 Answers

2
votes

You'll want to read XEP-0045, "Multi-User Chat". You need to enter the room before sending a message to it. For a quick fix, see section 7.1.1, which shows how to join a room using a simplified (older) protocol:

<presence
    to='[email protected]/thirdwitch'/>

For the newer protocol, include an extra x tag from section 7.1.2:

<presence
    to='[email protected]/thirdwitch'>
  <x xmlns='http://jabber.org/protocol/muc'/>
</presence>

I don't know your library, but you'll want code something like:

xmppClient.Send(new Presence
{
    To = "[email protected]/mynick",
});