Logging on to XMPP using agsxmpp

3.1k Views Asked by At

I have one problem when I tried to connect to server. i´m using the library agsXMPP and the next code. When I tried to connect to the server I can´t. I can´t do log with the server. I tried to send a message for some users too.

        agsXMPP.XmppClientConnection xmpp = new XmppClientConnection();
        string server = "ipServer";

        string user = "user";
        string pass = "password";
        int port = 5222;
        bool _wait = true;

        xmpp.Status = "available";
        xmpp.Show = ShowType.chat;
        xmpp.Priority = 1;
        xmpp.SendMyPresence();
        xmpp.Server = server;
        xmpp.Port = port;
        xmpp.Username = usuCon;
        xmpp.Password = usuCon;

        xmpp.Open();

        agsXMPP.Jid JID = new Jid("[email protected]);
        agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
        msg.Type = agsXMPP.protocol.client.MessageType.chat;
        msg.To = JID;
        msg.Body = "hi how are you? message" + DateTime.Now.ToString();



        xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); };
        agsXMPP.protocol.server.Presence presencia2 = new  agsXMPP.protocol.server.Presence();
        presencia2.Type = new PresenceType();
        xmpp.OnLogin += xmpp_OnLogin;

        Console.WriteLine("Wait");
        int i = 0;
        do
        {
            Console.Write(".");
            i++;
            if (i == 10)
                _wait = false;
            Thread.Sleep(1000);
        } while (_wait);


        Console.WriteLine("\n" + msg);
        Console.Read();
    }

    private void xmpp_OnLogin(object sender)
    {
        Console.WriteLine("yes");
    }
1

There are 1 best solutions below

0
On

I had this problem and I solved it by this code:

        XmppClientConnection xmpp = new XmppClientConnection();
        xmpp.ConnectServer = "ipServer";
        xmpp.Server = "domain name";
        xmpp.Port = 5222; 
        xmpp.Username = "my userName";
        xmpp.Password = "my password";
        xmpp.Open();

xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);