Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
ethush #1
Member since May 2012 · 2 posts · Location: Oaxaca, Mexico
Group memberships: Members
Show profile · Link to this post
Subject: OnMessage function is cyclized
Hello to you all!, My problem is this, I coded a simple client in C# for sending group messages (at different customer accounts that have on their lists, it is not a chat room), the problem I have is when the client program receives the messages that are cycled  and this does not send the message. This is the code I'm using the function onMessage


static void cliente_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            string name="", bot_name="";
            int id_usr=0;


            NpgsqlCommand findBotName= con.CreateCommand();
           
            string mailsender = msg.From.User +"@"+msg.From.Server;
            findBotName.CommandText = "select * from usuario where email='" + mailsender+"'";
           

            NpgsqlDataReader rec = findBotName.ExecuteReader();


            while (rec.Read())
            {
                name = rec.GetString(0);
                bot_name = rec.GetString(1);
                id_usr = rec.GetInt32(2);
            }
           

            findBotName.Dispose();
            rec.Dispose();

            //get mail list to send message
            NpgsqlCommand toSend = con.CreateCommand();
            toSend.CommandText = "select mail from usr where trim(mail) like '%domain.org' and  trim(mail)!='"+mailsender+"'";

           
            NpgsqlDataReader recept = toSend.ExecuteReader();
   
           
            //Send messages to users
            Console.WriteLine(msg.From.User + "@" + msg.From.Server + " says: " + msg.Body);
            while(recept.Read())
            {
                Console.WriteLine("Send to: {0} message is: {1}", recept.GetString(0), msg.Body);
                client.Send(new agsXMPP.protocol.client.Message(recept.GetString(0), MessageType.chat, bot_name + " say: " + msg.Body));
            }
           
            toSend.Dispose();
            recept.Dispose();
   }

My problem is that the function is cycled and shows no error message.

This is main function:

public static agsXMPP.XmppClientConnection cliente = new agsXMPP.XmppClientConnection();
public static Jid user = new Jid("test@domain.org");
public static Jid pass = new Jid("test");
static void Main(string[] args)
        {
            try
            {
                con.ConnectionString = "Server= 127.0.0.1;Port=5432;User Id=*;Password=*;Database=*;";
                try
                {
                    con.Open();
                }
                catch (NpgsqlException npg_exception)
                {
                    con.Close();
                    Console.WriteLine(npg_exception.Message);
                    throw new Exception(npg_exception.Message);

                }
                finally
                {
                    Console.WriteLine("DB connection ok...");
                    Console.WriteLine();
                    Console.WriteLine();
                }
            }
            catch (NpgsqlException npg_exception)
            {
                con.Close();
                Console.WriteLine(npg_exception.Message);
                throw new Exception(npg_exception.Message);
            }

            Console.WriteLine("Try to connect server talk.google.com..");
            Console.WriteLine();
            try
            {
               
                cliente.Server = "google.com";
                cliente.ConnectServer = "talk.google.com";
                cliente.Port = 5222;
                cliente.AutoRoster = true;
                cliente.AutoPresence = true;
                cliente.AutoResolveConnectServer = false;
               
                cliente.OnLogin += new ObjectHandler(cliente_OnLogin);
                cliente.OnError += new ErrorHandler(cliente_OnError);
                cliente.OnMessage += new agsXMPP.protocol.client.MessageHandler(cliente_OnMessage);
               
                cliente.Open(user, pass, "home");
            }
            catch (agsXMPP.exceptions.XmlRpcException xml_ex)
            {
                con.Close();
                Console.WriteLine(xml_ex.Message);
                throw new Exception(xml_ex.Message);
            }
            finally
            {
                Console.ReadKey();
            }
     }

Any help or ideas is welcome.

**Sorry for my inconsistency in few words was made with the google translator.
The author has attached one file to this post:
pruebaLog.txt 354.3 kBytes
You have no permission to open this file.
This post was edited on 2012-05-18, 18:56 by ethush.
Edit reason: Attach XML Log file
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Sorry, but I don't understand you question, and I don't understand what you mean with "cyclized".
Avatar
ethush #3
Member since May 2012 · 2 posts · Location: Oaxaca, Mexico
Group memberships: Members
Show profile · Link to this post
The situation is when I send the message that a user will send the customer must send to other users who are taken from a database of emails, includes program in onMessage function is executed many times and I have to stop the program manually, I console outputs the messages begin to replicate but these never reach the recipients.

An example output is as follows:
18/05/2012;<message to="pzarate@cmicoaxaca.org.mx" type="chat"><body> dice: prueba3</body></message>;
18/05/2012;<message xmlns="jabber:client" from="pzarate@cmicoaxaca.org.mx" to="test@cmicoaxaca.org.mx/homeD6F91422" type="error"><body> dice: prueba3</body><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></message>;
18/05/2012;<message xmlns="jabber:client" from="emanuel.ruiz@cmicoaxaca.org.mx" to="test@cmicoaxaca.org.mx/homeD6F91422" type="error"><body> dice: prueba3</body><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></message>;
18/05/2012;<message to="vsantos@cmicoaxaca.org.mx" type="chat"><body>Emanuel dice:  dice: prueba3</body></message>;
18/05/2012;<message to="pzarate@cmicoaxaca.org.mx" type="chat"><body>Emanuel dice:  dice: prueba3</body></message>;
18/05/2012;<message to="asantiago@cmicoaxaca.org.mx" type="chat"><body>Raziel dice: Viri dice: Teo dice:  dice: prueba3</body></message>;
18/05/2012;<message to="omartinez@cmicoaxaca.org.mx" type="chat"><body>Raziel dice: Viri dice: Teo dice:  dice: prueba3</body></message>;


I attached a log in xml with the outputs in the initial thread, you can see the moment when the message begins to duplicate an only see the next message
 
    error code="503" type="cancel"

in debug mode step by step I see the function onMessage the program executes in loop and not stop until I have to stop debugging.

I thought that states of users, and for that reason can not send messages, I tested with customers in "available" to all users in this state the program has no problems, but if the user state is occupied or unavailable or disconnected the program fails and the function I mentioned starts to run indefinitely, is there any way to know the status of users? or set a priority level to send the message anyway?

Your help is much appreciated
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You are sending a message to a resource which is not available. This is why the server replies with error. And I guess you don't check for error messages in your OnMessage handler and send it again and run in an infinite loop.

You get the presence and resource of your contacts in the OnPresence handler. So when a resource is not available then you should not send the message to this resource (full Jid). Either don't send the message at all, or send it to a bare Jid, then the server stores it offline and delivers it when the user goes online again.
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:
Forum: agsXMPP RSS