簡體   English   中英

身份驗證C#的Jabber客戶端問題

[英]Jabber client issue with Authentication c#

下面給出了一個示例控制台應用程序,該應用程序使用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();
    }
}

在您的代碼示例中,您使用sample@jabber.org作為用戶名。 這是完整的裸機Jid。 xmpp中的用戶名(節點部分)僅是“ @”之前的部分。 因此,嘗試使用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