Jabber客户端问题与身份验证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@jabber.org 。
j.User = "sample";
j.Server = "jabber.org";
j.Password = "secret";
链接地址: http://www.djcxy.com/p/94147.html
上一篇: Jabber client issue with Authentication c#
下一篇: Join XMPP MUC with one JID simultaneously from different resources with openfire