简体   繁体   English

身份验证C#的Jabber客户端问题

[英]Jabber client issue with Authentication c#

Given below is a sample console application uses jabber-net client for sending a sample test message after authenticating the connection. 下面给出了一个示例控制台应用程序,该应用程序使用jabber-net客户端在验证连接后发送示例测试消息。 I am receiving error while authenticating the login request.Error is given below. 验证登录请求时收到错误。错误在下面给出。

"Unable to read data from the transport connection: A non-blocking socket operation could not be completed immediately. " “无法从传输连接中读取数据:无法立即完成无阻塞套接字操作。”

I am new into this XMPP. 我是这个XMPP的新手。 So many projects available online but none of them found relevent. 网上有如此多的项目可用,但都没有找到相关的内容。 Please provide with your valuable information or links that can be useful for developing a free jabber client library for my application. 请提供您的宝贵信息或链接,这些信息或链接对于为我的应用程序开发免费的jabber客户端库很有用。

Sample code is attached below! 示例代码附在下面!

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

In your code example you use sample@jabber.org as username. 在您的代码示例中,您使用sample@jabber.org作为用户名。 This is the complete bare Jid. 这是完整的裸机Jid。 The username (node part) in xmpp is the part before the "@" only. xmpp中的用户名(节点部分)仅是“ @”之前的部分。 So try to use sample as username instead of sample@jabber.org . 因此,尝试使用sample作为用户名,而不是sample@jabber.org

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM