简体   繁体   English

XMPP(Xamarin.Android)中的主机未知异常

[英]Host-unknown exception in XMPP (Xamarin.Android)

I continue with a connection to server. 继续连接到服务器。 I have succesfully added XMPP library to my Xamarin.Android project, but when I try to make a simple connection: 我已成功将XMPP库添加到我的Xamarin.Android项目中,但是当我尝试建立简单连接时:

        using (var cl = new XmppClient(hostname,username,password))
        {
            cl.Connect();

            Console.WriteLine("Contacts on " + cl.Jid.Node + "'s contact-list:");
            foreach (var item in cl.GetRoster())
                Console.WriteLine(" - " + item.Jid);
        }     

this case occure: 这种情况发生:

09-25 12:37:14.713 I/mono-stdout( 2821): _xmpp-client._tcp.jabbim.cz 2454 IN SRV 20 0 5222 lb2-hap.jabbim.cz
  |--- Name _xmpp-client._tcp.jabbim.cz
09-25 12:37:14.717 I/mono-stdout( 2821):   |--- Name _xmpp-client._tcp.jabbim.cz
  |--- Port: 5222
09-25 12:37:14.721 I/mono-stdout( 2821):   |--- Port: 5222
09-25 12:37:14.729 I/mono-stdout( 2821):   |--- Priority20
  |--- Priority20
09-25 12:37:14.741 I/mono-stdout( 2821):   |--- Type Srv
  |--- Type Srv
  |--- Target: lb2-hap.jabbim.cz
09-25 12:37:14.765 I/mono-stdout( 2821):   |--- Target: lb2-hap.jabbim.cz
_xmpp-client._tcp.jabbim.cz 2454 IN SRV 10 0 5222 lb1-hap.jabbim.cz
09-25 12:37:14.773 I/mono-stdout( 2821): _xmpp-client._tcp.jabbim.cz 2454 IN SRV 10 0 5222 lb1-hap.jabbim.cz
  |--- Name _xmpp-client._tcp.jabbim.cz
09-25 12:37:14.781 I/mono-stdout( 2821):   |--- Name _xmpp-client._tcp.jabbim.cz
  |--- Port: 5222
09-25 12:37:14.781 I/mono-stdout( 2821):   |--- Port: 5222
  |--- Priority10
09-25 12:37:14.785 I/mono-stdout( 2821):   |--- Priority10
09-25 12:37:14.789 I/mono-stdout( 2821):   |--- Type Srv
  |--- Type Srv
  |--- Target: lb1-hap.jabbim.cz
09-25 12:37:14.797 I/mono-stdout( 2821):   |--- Target: lb1-hap.jabbim.cz
09-25 12:37:15.457 D/Mono    ( 2821): Assembly Ref addref System.Xml[0xb7c5d400] -> System[0xb7c24320]: 7
09-25 12:37:16.033 D/Mono    ( 2821): DllImport attempting to load: '/system/lib/liblog.so'.
09-25 12:37:16.057 D/Mono    ( 2821): DllImport loaded library '/system/lib/liblog.so'.
09-25 12:37:16.057 D/Mono    ( 2821): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
09-25 12:37:16.057 D/Mono    ( 2821): Searching for '__android_log_print'.
09-25 12:37:16.065 D/Mono    ( 2821): Probing '__android_log_print'.
09-25 12:37:16.065 D/Mono    ( 2821): Found as '__android_log_print'.
09-25 12:37:16.085 I/MonoDroid( 2821): UNHANDLED EXCEPTION:
09-25 12:37:16.085 I/MonoDroid( 2821): Sharp.Xmpp.XmppDisconnectionException: Unrecoverable stream error: host-unknown
09-25 12:37:16.093 I/MonoDroid( 2821): at Sharp.Xmpp.Core.StreamParser.NextElement (string[]) <IL 0x0015d, 0x00713>
09-25 12:37:16.093 I/MonoDroid( 2821): at Sharp.Xmpp.Core.XmppCore.InitiateStream (string) <IL 0x000b5, 0x002eb>
09-25 12:37:16.093 I/MonoDroid( 2821): at Sharp.Xmpp.Core.XmppCore.SetupConnection (string) <IL 0x00007, 0x00053>
09-25 12:37:16.097 I/MonoDroid( 2821): at Sharp.Xmpp.Core.XmppCore.Connect (string) <IL 0x0004f, 0x001bf>
09-25 12:37:16.097 I/MonoDroid( 2821): at Sharp.Xmpp.Im.XmppIm.Connect (string) <IL 0x00078, 0x002b7>
09-25 12:37:16.101 I/MonoDroid( 2821): at Sharp.Xmpp.Client.XmppClient.Connect (string) <IL 0x00007, 0x00033>

It seems something is missing in a configuration. 似乎配置中缺少某些内容。 Thanks a lot for reply. 非常感谢您的回复。

According to this page the exception: 根据此页面的异常:

Sharp.Xmpp.XmppDisconnectionException: Unrecoverable stream error: host-unknown

refers to: 指:

the value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server. 流头中的启动实体提供的“ to”属性的值与服务器托管的主机名不对应。

So the hostname you are using to establish the connection does not match the hostname of the server. 因此,用于建立连接的主机名与服务器的主机名不匹配。 So are you sure that the hostname you are using is the right one and the server uses exactly this hostname? 因此,您确定所使用的主机名正确,并且服务器使用的正是该主机名吗?

Probably this is an issue with DNS resolution in Android or server configuration. 这可能是Android或服务器配置中的DNS解析问题。 Sharp.Xmpp uses the https://arsofttoolsnet.codeplex.com/ package. Sharp.Xmpp使用https://arsofttoolsnet.codeplex.com/包。

$ nslookup -querytype=SRV _xmpp-client._tcp.jabbim.cz Server: 100.72.64.140 Address: 100.72.64.140#53 $ nslookup -querytype = SRV _xmpp-client._tcp.jabbim.cz服务器:100.72.64.140地址:100.72.64.140#53

Non-authoritative answer: _xmpp-client._tcp.jabbim.cz service = 10 0 5222 lb1-hap.jabbim.cz. 非权威性答案:_xmpp-client._tcp.jabbim.cz服务= 10 0 5222 lb1-hap.jabbim.cz。 _xmpp-client._tcp.jabbim.cz service = 20 0 5222 lb2-hap.jabbim.cz. _xmpp-client._tcp.jabbim.cz服务= 20 0 5222 lb2-hap.jabbim.cz。

Authoritative answers can be found from: lb1-hap.jabbim.cz internet address = 88.86.102.58 lb2-hap.jabbim.cz internet address = 37.157.196.214` 权威答案可以从以下网址找到:lb1-hap.jabbim.cz互联网地址= 88.86.102.58 lb2-hap.jabbim.cz互联网地址= 37.157.196.214`

According to your snippet, resolution is correct, and your are connecting to lb1-hap.jabbim.cz. 根据您的代码段,分辨率是正确的,并且您正在连接到lb1-hap.jabbim.cz。 Could it be that from console you are connecting to lb2, and lb2, lb1 have a different configuration? 可能是您从控制台连接到lb2,而lb2,lb1具有不同的配置吗?

Use this: 用这个:

client = new XmppClient(hostname, username, password);
client.Hostname = hostname;
client.Connect();

The reason seems to be a bug in Sharp.Xmpp. 原因似乎是Sharp.Xmpp中的错误。 In the XmppClient() function the hostname gets altered to the DNS Lookup, in your case lb1-hap.jabbim.cz . XmppClient()函数中,将主机名更改为DNS查找,在您的情况下为lb1-hap.jabbim.cz

Later in the Connect() function, the first XML Stanza is send to the same hostname "to:lb1-hap.jabbim.cz" . 稍后在Connect()函数中,第一个XML Stanza被发送到相同的主机名"to:lb1-hap.jabbim.cz" Then the server responses correctly with Unknown Host because it wants jabbim.cz 然后,服务器会使用“ Unknown Host正确响应,因为它需要jabbim.cz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM