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

Session establishment failed #34

Open Marcpellet opened 7 years ago

Marcpellet commented 7 years ago

Hello

I use openfire 4.0.2 on windows 7 and sharp.xmpp to communicate with the server. Everything worked fine during the testing phase when i used the same name for hostname and server name. I used the example of xmpp connection found in the documentation.

I tried to reinstall the server using a different name for server name and I am unable to connect to the server. The instruction client.connect() rise an exception of type: Exception:Sharp.Xmpp.XmppErrorException: Session establishment failed.

I saw that issue #9 already talks about this exception and tried to enable log plugin to have more information about the bug, but logs are totally unreadable.

Is there any special configuration to change when both server and host name are different or did I miss something ?

jpenny1993 commented 7 years ago

I'm also using openfire 4.0.2 on Win 2012 R2 an it's working fine (but mine are named the same). I might have some free time to check this when I get home.

As a temporary fix you could modify your hosts file so that your machine domain matches your server name.

Are you if sure this is happening in EstablishSession() on connect and not on authenticate? I've had to make my harness ignore exceptions from authenticate and then double check it is authenticated to be able to get around a stream termination bug.

Also could you post a pastebin of the exception details? It might be of help us solve this.

Marcpellet commented 7 years ago

Thanks for your answer

here is the complete stack trace:


L'exception S22.Xmpp.XmppErrorException n'a pas été gérée
  HResult=-2146233088
  Message=Session establishment failed.
  Source=S22.Xmpp
  StackTrace:
       à S22.Xmpp.Im.XmppIm.EstablishSession()
       à S22.Xmpp.Im.XmppIm.Connect(String resource)
       à S22.Xmpp.Client.XmppClient.Connect(String resource)
       à testSharpXmpp.Program.sendMessages(String hostname, String username, String password, String recipient) dans c:\Users\Marc\Documents\Cours\test c#\testSharpXmpp\testSharpXmpp\Program.cs:ligne 78
       à testSharpXmpp.Program.Main(String[] args) dans c:\Users\Marc\Documents\Cours\test c#\testSharpXmpp\testSharpXmpp\Program.cs:ligne 52
       à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
Marcpellet commented 7 years ago

Oups i didn't notice I had an old version on my test project, I changed to the last library release and the exception persist:

  L'exception Sharp.Xmpp.XmppErrorException n'a pas été gérée
  HResult=-2146233088
  Message=Session establishment failed for Hostname: marcpc
  Source=Sharp.Xmpp
  StackTrace:
       à Sharp.Xmpp.Im.XmppIm.EstablishSession() dans c:\Users\Marc\Documents\Cours\BA6\TB\sharp.xmpp\Sharp.Xmpp\Im\XmppIm.cs:ligne 1528
       à Sharp.Xmpp.Im.XmppIm.Connect(String resource) dans c:\Users\Marc\Documents\Cours\BA6\TB\sharp.xmpp\Sharp.Xmpp\Im\XmppIm.cs:ligne 372
       à Sharp.Xmpp.Client.XmppClient.Connect(String resource) dans c:\Users\Marc\Documents\Cours\BA6\TB\sharp.xmpp\Sharp.Xmpp\Client\XmppClient.cs:ligne 655
       à testSharpXmpp.Program.sendMessages(String hostname, String username, String password, String recipient) dans c:\Users\Marc\Documents\Cours\test c#\testSharpXmpp\testSharpXmpp\Program.cs:ligne 78
       à testSharpXmpp.Program.Main(String[] args) dans c:\Users\Marc\Documents\Cours\test c#\testSharpXmpp\testSharpXmpp\Program.cs:ligne 52
       à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
nairbijesh commented 7 years ago

Well i had same issue and solved it by modifying Library source code. Basically cause for the issue is Library could not able to do "Session Establishment" [XMPP RFC 3921, Section 3] if Host name and Server Name is different.

To solve, i suggest you to do following modification in Library source code.

  1. XMPPClient class should accept one additional parameter 'ServerName' same like Hostname.
  2. EstablishSession() method written in XmppIm Class should use 'Servername' instead of 'Hostname' for Session IQ Request.
stevenlivz commented 7 years ago

This is quite a significant bug and i'm surprised not to have seen this more. Thanks for the tip - i will fork and mod the source.

dgenezini commented 7 years ago

Any updates on this? What is this Server Name?

cimframe commented 7 years ago

nairbijesh - can you please post the actual code for the necessary change?

Thanks, Steve

VitorCioletti commented 5 years ago

@stevenlivz actually have done a nice job to fix this. See #41. Unfortunately there is no published package using this modification. I have asked permission for @stevenlivz to fork his mod in order to publish and maintain it. I'm still getting into the source code but soon it will be published.