2010-07-09 48 views
3

我想要开始使用agsXMPP,但我遇到了一些问题。我试图运行此代码:为什么我无法使用agsXMPP连接到Google Talk?

using System; 
using agsXMPP; 

namespace TestAgs 
{ 
    class MainClass 
    { 
     public static void Main (string[] args) 
     { 
      XmppClientConnection connection = new XmppClientConnection(); 
      connection.OnLogin += delegate { 
       Console.WriteLine ("logged in"); 
      }; 
      connection.Server = "gmail.com"; 
      connection.ConnectServer = "talk.google.com"; 
      connection.Username = "my username"; // I tried both with and without '@gmail.com' 
      connection.Password = "my password"; 
      connection.Open(); 
     } 
    } 
} 

这个编译好,但是当我尝试运行它时,没有任何反应。它运行并没有任何错误地完成,但“登录”永远不会打印到控制台。我究竟做错了什么?

如果它有所作为,我在Ubuntu 10.04上使用Mono 2.4。

回答

4

除非connection.Open()块,我怀疑,问题是你的程序命中main的结尾,因此它完成运行并结束。

你怎么想保持它退出取决于你正在尝试做的,但一个方法是一个ManualResetEvent的:

var mre = new System.Threading.ManualResetEvent (false); 
mre.WaitOne(); 

当然,现在你可以有相反的问题,有没有方式为您的应用程序完成。

1

我认为问题是端口号。您没有在连接中提供5222或5223。

+0

感谢Pujan,jpobst的提示,它可以使用或不使用端口号。默认情况下,Jabber参考中设置了 – 2010-07-10 16:55:02

+0

端口号。 – RobertPitt 2010-07-12 11:12:52

1

只需添加Console.ReadLine();之后行'connection.Open();'

0
// connection.Server = "gmail.com"; 
connection.ConnectServer = "talk3.l.google.com"; OR 
connection.ConnectServer = "talk2.l.google.com"; 
connection.Username = "my username"; // I tried both with and without '@gmail.com' 
connection.Password = "my password"; 
connection.Open(); 

talk3.l.google对我很好。

相关问题