Subject: connection wont stay active after method returns
I have a button that is on a form. The event for the buttons creates an instance of XmppClientConnection and assigns it to a class variable.
when the method returns the user that got logged in appears offline
I put a sleep in there and that shows that the connection stays active until the sleep runs out and the method returns.
Is this normal? I would have thought this code would have logged in the user and kept it active till I called the close() method
private void cbChat_CheckedChanged(object sender, EventArgs e)
{
if (this.cbChat.Checked)
{
xmpp = new XmppClientConnection();
xmpp.Server = "gmail.com";
xmpp.ConnectServer = "talk.google.com";
xmpp.Username = "adaptiveai@gmail.com";
xmpp.Password = "a2i2april";
xmpp.OnLogin += new ObjectHandler(onLogin);
xmpp.OnMessage += new agsXMPP.XmppClientConnection.MessageHandler(onMessage);
xmpp.Open();
this.cbChat.Text = "Connecting...";
Application.DoEvents();
System.Threading.Thread.Sleep(9000);
}
else
{
xmpp.Close();
xmpp = null;
this.cbChat.Text = "Connect";
}
}
private void onLogin(object Sender)
{
xmpp.SendMyPresence();
// xmpp.Send(new agsXMPP.protocol.client.Message("foo@gmail.com",
// agsXMPP.protocol.client.MessageType.chat, "Hello, how are you?"));
this.cbChat.Text = "Disconnect";
}
private void onMessage(object sender, agsXMPP.protocol.client.Message msg)
{
Console.WriteLine(msg.Body);
}
when the method returns the user that got logged in appears offline
I put a sleep in there and that shows that the connection stays active until the sleep runs out and the method returns.
Is this normal? I would have thought this code would have logged in the user and kept it active till I called the close() method
private void cbChat_CheckedChanged(object sender, EventArgs e)
{
if (this.cbChat.Checked)
{
xmpp = new XmppClientConnection();
xmpp.Server = "gmail.com";
xmpp.ConnectServer = "talk.google.com";
xmpp.Username = "adaptiveai@gmail.com";
xmpp.Password = "a2i2april";
xmpp.OnLogin += new ObjectHandler(onLogin);
xmpp.OnMessage += new agsXMPP.XmppClientConnection.MessageHandler(onMessage);
xmpp.Open();
this.cbChat.Text = "Connecting...";
Application.DoEvents();
System.Threading.Thread.Sleep(9000);
}
else
{
xmpp.Close();
xmpp = null;
this.cbChat.Text = "Connect";
}
}
private void onLogin(object Sender)
{
xmpp.SendMyPresence();
// xmpp.Send(new agsXMPP.protocol.client.Message("foo@gmail.com",
// agsXMPP.protocol.client.MessageType.chat, "Hello, how are you?"));
this.cbChat.Text = "Disconnect";
}
private void onMessage(object sender, agsXMPP.protocol.client.Message msg)
{
Console.WriteLine(msg.Body);
}