使用 agsxmpp 登录 XMPP

Posted

技术标签:

【中文标题】使用 agsxmpp 登录 XMPP【英文标题】:Logging on to XMPP using agsxmpp 【发布时间】:2015-01-14 22:23:22 【问题描述】:

我在尝试连接服务器时遇到了一个问题。 我正在使用库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");
    

【问题讨论】:

你能告诉我们错误吗? 我没有错误。问题是当我尝试执行 xmpp.open() 时不要这样做。我可以使用 xmpp_OnLogin 方法进行验证。我调试了我的项目,并且 xmpp_OnLogin 从未被调试过。 IPv6 应该被禁用。按照此处的说明进行操作:techunboxed.com/2014/10/how-to-disable-ipv6-in-windows-10.html 【参考方案1】:

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

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

【讨论】:

以上是关于使用 agsxmpp 登录 XMPP的主要内容,如果未能解决你的问题,请参考以下文章

无法使用 agsXMPP 连接到 GCM(无法建立连接,因为目标机器主动拒绝它)

如何解析 XMPP?

无法将 agsXmpp 客户端连接到 eJabberd 服务器

使用 agsxmpp 库从 xml 节点获取信息

如何通过 vb.net 中的 xmpp dll 连接 facebook?

如何在 Agsxmpp 中获取离线消息的数量?