【问题标题】:Jabber client issue with Authentication c#身份验证 c# 的 Jabber 客户端问题
【发布时间】:2013-04-26 13:21:53
【问题描述】:

下面是一个示例控制台应用程序,它使用 jabber-net 客户端在验证连接后发送示例测试消息。 我在验证登录请求时收到错误。错误如下所示。

“无法从传输连接中读取数据:无法立即完成非阻塞套接字操作。”

我是这个 XMPP 的新手。网上有这么多项目,但没有一个是相关的。 请提供您的宝贵信息或链接,这些信息或链接可用于为我的应用程序开发免费的 jabber 客户端库。

下面附上示例代码!

class Program
{
    // we will wait on this event until we're done sending
    static ManualResetEvent done = new ManualResetEvent(false);
    // if true, output protocol trace to stdout
    const bool VERBOSE = true;
    const string TARGET = "sample@example.com";


    static void Main(string[] args)
    {
        JabberClient j = new JabberClient();
        j.User = "sample@jabber.org";
        j.Server = "jabber.org"; // use gmail.com for GoogleTalk
        j.Password = "samplePassword";


        // don't do extra stuff, please.
        j.AutoPresence = false;
        j.AutoRoster = false;
        j.AutoReconnect = 30;

        // listen for errors.  Always do this!
        j.OnError += new bedrock.ExceptionHandler(j_OnError);

        // what to do when login completes
        j.OnAuthenticate += new bedrock.ObjectHandler(j_OnAuthenticate);

        // listen for XMPP wire protocol
        if (VERBOSE)
        {
           // j.OnLoginRequired += new bedrock.ObjectHandler(j_OnLoginRequired);
            j.OnReadText += new bedrock.TextHandler(j_OnReadText);
            j.OnWriteText += new bedrock.TextHandler(j_OnWriteText);
        }

        // Set everything in motion
        j.Connect();

        // wait until sending a message is complete
        done.WaitOne();

        // logout cleanly
        j.Close();
    }

    static void j_OnWriteText(object sender, string txt)
    {
        if (txt == " ") return;  // ignore keep-alive spaces
        Console.WriteLine("SEND: " + txt);
    }

    static void j_OnReadText(object sender, string txt)
    {
        if (txt == " ") return;  // ignore keep-alive spaces
        Console.WriteLine("RECV: " + txt);
    }

    static void j_OnAuthenticate(object sender)
    {
        // Sender is always the JabberClient.
        JabberClient j = (JabberClient)sender;
        j.Message(TARGET, "test");

        // Finished sending.  Shut down.
        done.Set();
    }

    static void j_OnError(object sender, Exception ex)
    {
        // There was an error!
        Console.WriteLine("Error: " + ex.ToString());

        // Shut down.
        done.Set();
    }
}

【问题讨论】:

    标签: c# xmpp chat publish-subscribe


    【解决方案1】:

    在您的代码示例中,您使用 sample@jabber.org 作为用户名。这是完整的裸吉德。 xmpp 中的用户名(节点部分)仅是“@”之前的部分。所以尝试使用 sample 作为用户名,而不是 sample@jabber.org

    j.User = "sample";
    j.Server = "jabber.org";
    j.Password = "secret";
    

    【讨论】:

    • 我像你说的那样做了同样的事情。我仍然收到同样的错误。 “无法从传输连接读取数据:无法立即完成非阻塞套接字操作。” 我认为问题出在正在使用的端口上。
    • 如果我指定端口。我收到以下错误。 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应 208.68.163.220:420
    • 那么请将您的 Xml 调试输出附加到您的问题中。然后我们可以看看它是否获得了连接,以及它在哪里停止。
    • 您在 Server 属性中有 talk.google.com,它必须是 gmail.com 或使用 google 应用程序时您的 google ID 中 @ 之后的任何内容
    • 您是否在 jabber.net 中启用了 SRV 解析?我认为 208.68.163.220 不是 jabber.org 的正确 IP 地址
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    相关资源
    最近更新 更多