使用agsxmpp登录XMPP

时间:2015-01-14 22:23:23

标签: c# agsxmpp

我尝试连接服务器时遇到一个问题。 我正在使用库agsXMPP和下一个代码。当我尝试连接到服务器时,我无法做到。我不能用服务器登录。我也试图为一些用户发送消息。

        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("example@org.es);
        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 个答案:

答案 0 :(得分:0)

我遇到了这个问题,我用这段代码解决了这个问题:

        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);