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. 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. 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.
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. This is the complete bare Jid. The username (node part) in xmpp is the part before the "@" only. So try to use sample as username instead of sample@jabber.org .
j.User = "sample";
j.Server = "jabber.org";
j.Password = "secret";
链接地址: http://www.djcxy.com/p/94148.html
上一篇: 如何在XMPP中阻止匿名用户
下一篇: Jabber客户端问题与身份验证c#