Not logged in. · Lost password · Register
Forum: XMPP Protocol RSS
Avatar
ebmifa #1
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
Subject: Joining a room and sending a message
Hi,
I am trying create a c# app using agsXMPP to be used in our nightly build process to broadcast messages to a particular room on our Jabber Wildfire server. So far I am able to login to our wildfire server using agsXMPP and send messages to users, but not to a room. I figured that I need to join a room first and then send a message but I can't seem to find any examples on how to do that with agsXMPP. Has anyone else tried to do this and is willing to share code?

Thanks
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

the MiniClient examples supports groupchat. So take a look at it, all the code you need should be there.
Also take a look at the MucManager class. It's a wrapper for easier access to all groupchat related classes and functions.

Alex
Avatar
ebmifa #3
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
Thank you for your prompt response. I think I have found the example you are referring to.
So I have the following code:

            ....
            jClient = new XmppClientConnection(); // Jabber Client Instance
            jClient.OnLogin += new ObjectHandler(jClient_OnLogin);
            jClient.OnError += new agsXMPP.ErrorHandler(jClient_OnError);
           
            jClient.Server = "*****";
            jClient.Username = "*****";
            jClient.Password = "*****";
            jClient.Port = 5222;
            jClient.Resource = "jabberin";
            jClient.Priority = 5;
            jClient.Status = "Online";
            jClient.Show = ShowType.NONE;
   
            try
            {
                jClient.Open();              
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            ......

private static void jClient_OnLogin(object sender)
        {
            jClient.SendMyPresence();

            MucManager mucManager = new MucManager(jClient);
            Jid Room = new Jid("room_name@eng-ops");
            mucManager.AcceptDefaultConfiguration(Room);
            mucManager.JoinRoom(Room, "room_name");
            jClient.Send(new Message(Room, "This is a test"));
            jClient.Close();
        }

For some reason the jClient_OnLogin function never gets called when I try to open the jClient connection. Am I not calling the jclient.open() properly?

Thanks
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

you get the OnLogin event after successful authentication. If you don't get this event there must be an authentication problem.

Alex
Avatar
ebmifa #5
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
So my athentication credentials work just fine, even in the miniclient example. I have the following code and can't figure out why I can authenticate:

using System;
using System.Collections.Generic;
using System.Text;
using agsXMPP;
using agsXMPP.protocol;
using agsXMPP.protocol.client;
using agsXMPP.protocol.x.muc;
using System.Threading;

namespace SendToJabber
{
    public class Program
    {
        private static XmppClientConnection jClient;

        public static void Main(string[] args)
        {
            jClient = new XmppClientConnection(); // Jabber Client Instance
            /**
             * Events for agsXMPP library
             * */
            jClient.OnLogin += new ObjectHandler(jClient_OnLogin);
            jClient.OnError += new ErrorHandler(jClient_OnError);
           
            jClient.Server = "eng-ops";
            jClient.Username = "*****";
            jClient.Password = "*****";
            jClient.Port = 5222;
            jClient.Resource = "jabberin";
            jClient.Priority = 10;
            jClient.UseSSL = false;
            jClient.SocketConnectionType = agsXMPP.net.SocketConnectionType.Direct;
            jClient.UseStartTLS = true;
            jClient.AutoResolveConnectServer = true;
            jClient.RegisterAccount = false;
   
            try
            {
                jClient.Open();              
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        private static void jClient_OnLogin(object sender)
        {
            jClient.SendMyPresence();
            MucManager mucManager = new MucManager(jClient);
            Jid Room = new Jid("4xBuilds@eng-ops");
            mucManager.AcceptDefaultConfiguration(Room);
            mucManager.JoinRoom(Room, "4xBuilds");
            jClient.Send(new Message(Room, "This is a test"));
            jClient.Close();
        }

        private static void jClient_OnError(object sender, Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        private static void jClient_OnMessage(object sender, Message msg)
        {
            Console.WriteLine("Sending text: '" + msg.Body + "' to: " + sendTo);
        }
    }
}

None of the events seem be called and I get no exceptions.

Thanks
Avatar
Alex #6
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Looks like this is a console application. Your console application terminates after it leaves the Main function. The Open method is async and return immediately which terminates your program after the Open call. You have to prevent you code from terminating after opening the connection,

Alex
Avatar
ebmifa #7
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
Great point. I have made the necessary changes and now the on_login event works correctly, and I am able to login to the server and send messages to users.
Thanks
Avatar
ebmifa #8
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
One last question. For some reason I cannot joing the room by using mucmanager:
Here is the code that I am using:

            m_jClient.SendMyPresence();
            MucManager mucManager = new MucManager(m_jClient);
            Jid Room = new Jid("4xBuilds@conference.eng-ops");
            mucManager.AcceptDefaultConfiguration(Room);
            mucManager.JoinRoom(Room,"Builds");
            mucManager.LeaveRoom(Room, "Builds");
            m_jClient.Close();

Is the room format correct? I assume it should be room@conference.jabber_server, right?

Thanks
Avatar
Alex #9
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

if the room already exists then you only have to send your presence to the room which is done by the JoinRoom member of the MucManager.
If the room does not exists then you have to create it. Depending on your MUC component configuration the steps for creating a room can be different.

Alex
Avatar
ebmifa #10
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
The room does exist already, but nothing happens when I try to join it.
Avatar
Alex #11
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
After you successful joined a room the muc server sends presence packets which are the presences from all occupants.
Can you post your debug xm?

Alex
Avatar
ebmifa #12
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
This might sound dumb, but where do I capture the xm debug output?
Avatar
Alex #13
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
in the OnReadXML and OnWriteXml events.

Alex
Avatar
ebmifa #14
Member since Nov 2006 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
Turns out that my code was correct. I had to rooms with the same name for some reason, and once I have deleted the duplicate, everything worked. Thanks for much for your help.
Avatar
sreedevi1984 #15
Member since Oct 2006 · 38 posts
Group memberships: Members
Show profile · Link to this post
Subject: Declining the invitation for conference giving an error
 When an invitee declines the invitation of the invitor, the invitee is getting back an error- code :405 - You are not in this room.. Can anyone please help me to find out what's the problem...

        THIS IS THE XML DEBUG OF THE INVITOR :

RECV:
  <presence xmlns="jabber:client" from="test@conference.localhost/viji" to="viji@localhost/MiniClient">
    <priority>5</priority>
    <x xmlns="http://jabber.org/protocol/muc#user">
    <item affiliation="none" role="participant" />
        </x>
</presence>

RECV:
  <message xmlns="jabber:client" from="test@conference.localhost" to="viji@localhost/MiniClient" type="groupchat">
    <body>test</body>
</message>

RECV:
  <message xmlns="jabber:client" from="test@conference.localhost" to="viji@localhost/MiniClient" type="groupchat">
    <body>This room supports the MUC protocol.</body>
</message>

RECV:
  <message xmlns="jabber:client" from="test@conference.localhost" to="viji@localhost/MiniClient" type="groupchat">
    <body>viji has become available</body>

</message>


        THIS IS THE XML DEBUG OF THE INVITEE :

RECV:
 <message xmlns="jabber:client" from="test@conference.localhost" to="sree@localhost/MiniClient" type="normal">
    <subject>Invitation</subject>
    <body>You have been invited to the test@conference.localhost room by viji@localhost
        Reason: None given
    </body>
    <x xmlns="http://jabber.org/protocol/muc#user">
        <invite from="viji@localhost" />
    </x>
    <x xmlns="jabber:x:conference" jid="test@conference.localhost">None given</x>
 </message>

SEND:
 <message xmlns="jabber:client" to="test@conference.localhost">
    <x xmlns="http://jabber.org/protocol/muc#user">
        <decline to="viji@localhost/MiniClient" />
    </x>
</message>

RECV:
  <message xmlns="jabber:client" from="test@conference.localhost" to="sree@localhost/MiniClient" type="error">
    <x xmlns="http://jabber.org/protocol/muc#user">
        <decline to="viji@localhost/MiniClient" />
    </x>
    <error code="405">You are not in this room</error>
</message>

Thanks in advance,
Sreedevi.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: