首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用agsxmpp登录到XMPP

使用agsxmpp登录到XMPP
EN

Stack Overflow用户
提问于 2015-01-15 06:23:23
回答 1查看 3K关注 0票数 1

当我尝试连接到服务器时,我有一个问题。我使用的是库agsXMPP和下面的代码。当我尝试连接到服务器时,我无法连接到服务器。我无法在服务器上做日志。我也试着给一些用户发了条消息。

代码语言:javascript
复制
        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");
    }
EN

回答 1

Stack Overflow用户

发布于 2016-05-04 18:17:34

我有这个问题,我用下面的代码解决了这个问题:

代码语言:javascript
复制
        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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27953563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档