pgstath / Sharp.Xmpp

Sharp.Xmpp is looking for a maintainer! Unfortunatelly I do not have currently the time needed to maintain the library. Luckily a small but vibrant community has evolved around Sharp.Xmpp. If you would like to be the project's maintainer please sent an email to pgstath@gmail.com. This should include issues, tickets and commits that you have done for Sharp.Xmpp or other similar project. Sharp.Xmpp is a multiplatform, Windows and Android, .NET XMPP client assembly.Sharp.Xmpp supports IM functionality & a variety of XMPP extensions, is simple and is extensively tested against Android Xamarin. It is a fork of the currently frozen excellent S22.Xmpp project. Sharp.Xmpp will be at the FOSSDEM 2016 Real time DevRoom!
Other
84 stars 51 forks source link

Unrecoverable stream error: host-unknown #15

Open lovetox opened 8 years ago

lovetox commented 8 years ago

Hi,

i did setup a project with the basic xmpp server connect example from the documentation Documentation

it works with some servers, but i get the following exception

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

when i want to connect to jabber.at

you dont need an account to try this, it fails even before a connection is established.

someone on stackoverfllow had the same problem, but there was no solution posted

stackoverflow

pgstath commented 8 years ago

The DNS library was updated. Are you testing from Nuget or the main branch? Can you give it a try with this branch https://github.com/pgstath/Sharp.Xmpp/commit/24445c75426bcd7626558099a35a2a1c367c369d ?

lovetox commented 8 years ago

this didnt change anything

just try it yourself with these connection strings

string hostname = "jabber.at";
string username = "asd";
string password = "asd";

another server that is not working

jabber.ccc.de

lovetox commented 8 years ago

i found the error

if you connect with a connect string hostname = jabber.at

you get this

_xmpp-client._tcp.jabber.at. 66173 IN SRV 600 0 443 xmpp.jabber.at.
  |--- Name _xmpp-client._tcp.jabber.at.
  |--- Port: 443
  |--- Priority600
  |--- Type Srv
  |--- Target: xmpp.jabber.at.

_xmpp-client._tcp.jabber.at. 66173 IN SRV 300 0 5222 xmpp.jabber.at.
  |--- Name _xmpp-client._tcp.jabber.at.
  |--- Port: 5222
  |--- Priority300
  |--- Type Srv
  |--- Target: xmpp.jabber.at.

now the code sets xmpp.jabber.at as the new hostname.

and sends an xml stanza with "to:xmpp.jabber.at" element.

but thats a hostname thats not known to jabber.at cause it allows only for jabber.at

this happens in the new XmppClient() logic if you edit the variable before you call the Connect() function back to jabber.at everything works

a dirty fix for this problem is to overwrite the hostname after calling new XmppClient()

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

i dont know much about DNS and stuff, but if i do this like that everything works, which brings me to the question why this DNS lookup is even made in the firstplace, if you dont need it.

pgstath commented 8 years ago

now the code sets xmpp.jabber.at as the new hostname. and sends an xml stanza with "to:xmpp.jabber.at" element. but thats a hostname thats not known to jabber.at cause it allows only for jabber.at

Solid debugging thanks for this. I did not had the chance to test it myself but this helps greatly. DNS is used in order to resolve the XMPP domain to a XMPP server. This is resolved, but then it seems that instead of using the XMPP domain in the XMPP stanza the XMPP server is used. I will prepare a patch in order to fix the underlying bug in a more graceful way.

PavelPikat commented 7 years ago

Hi @pgstath. Are you still planning on patching this issue?

sbrl commented 7 years ago

I can confirm that @lovetox's solution works as expected for my domain starbeamrainbowlabs.com what's the status of a patch here, @pgstath?