ladendirekt / pjsip4net

A wrapper library exposing the pjsip library to the .NET world in a OO-friendly way.
71 stars 42 forks source link

connection failure fallback #43

Closed marknelissen closed 8 years ago

marknelissen commented 8 years ago

Hi,

Is there some kind of failover included in the library in case the connection and/or registration fails? Does the library retry to connect/register, or does this need to be piloted externally? If so, how is the best way to interact with the cycle to renew the connection/registration?

What happens on connection interruption? Does the library reconnect automatically on connection loss to the sip server? How to detect this, and fix it manually, if it does not?

I'm talking about the connection to the sip server, not to another sip client.

Regards,

Mark Nelissen

siniypin commented 8 years ago

Hi Mark,

long story short - there is no reliable way to get an instant notice that a connection was broken.
I mean, in general there is no way one can reliably tell whether the connection persists with ms precision, especially within wireless networks.

Long story:

  1. SIP is a transport agnostic protocol, meaning that one can 'connect' to SIP server using either UDP or TCP transport protocols.
  2. UDP and TCP differ significantly. With UDP transport one have no solid connection, rather a loose flow of outgoing and incoming datagram messages. Their sequence form a virtual connection state. Their timely arrival is a sign of a healthy connection. Matters get a little bit easier with TCP, as there is some sort of solid connection both ends can write to. However, even with TCP one should not expect an instant notice of a broken connection as there still is some sort of ping pong present on a kernel level.

So having that in mind I decided to check several theories:

So I setup a VM with a FreeSwitch server to connect to and performed tests using the pjsip4net.Console app that comes with a source code. That's what I found:

Nevertheless, there are options:

P.S. I shall encapsulate this logic within 1.4 version wrapper shortly, for everybody to take advantage of fast feedback with TCP transport. Mind it isn't real-time anyways.

P.P.S. You also asked whether library automatically reconnects whenever it looses a connection - it doesn't. Newer versions of pjsip do. So having a wrapper on top of the latest version of pjsip would solve that issue for you. Otherwise you have to do it on your own.

siniypin commented 8 years ago

Reconnecting means recovery from a disconnect. Pjsip periodically refresh registration with healthy connection, so you don't have to worry about that.

marknelissen commented 8 years ago

Hi,

Thank you very much for the detailed and in-depth explanation, as well as the time you are pouring into this.

I don't need ms precision, it is sufficient to know when the registration is not renewed, because of some error. However, it is not very clear to me which callback I should be registering on the wrapper to trigger another registration attempt manually. I did try some stuff, but I ended up triggering a new registration attempt, while the first was still busy. I did this by monitoring the state of the wrapper, which seems to not be the correct way of doing it, because it does not show when the registration is still trying, or else I checked the wrong state.

The use case I'm covering, is that the sip module is only part of a larger application on a public station. As such, the global application should not have to be restarted to recover from connection issues, since the end user will not have sufficient control to perform this operation. I want to put some watch dog function that automatically triggers reconnection (through registering again) in case the registration expires and fails to renew.

Also, are there any plans of upgrading the wrapper to the newer version of pjsip? Is the API much different? I barely understand how the current wrapper works, thus preventing me from offering you a pull request with the upgrade, at least right now.

siniypin commented 8 years ago

Hi,

it looks like a simple AccountStateChanged (https://github.com/siniypin/pjsip4net/blob/master/pjsip4net/Interfaces/IAccountManager.cs#L17) notification would be sufficient in your case. Objects of AccountStateChangedEventArgs class have a StatusCode property where values >= 400 mean something gone wrong.

Unfortunately, I have no time to add support for any newer versions of pjsip.

Cheers

siniypin commented 8 years ago

Hi Mark, did that work out for you?

marknelissen commented 8 years ago

Hi,

I haven't had time to work on the project again, but I will soon test it. I'll keep you informed of the result.

marknelissen commented 8 years ago

Hi,

I've finally gone for the solution to upgrade to the newer version 2.4.5 of pjsip, using the pjsua swig interface. The library is handling the reconnection quite nicely. The documentation is complete, but there are some stuff you need to manually do, which should for me be handled by the wrapper. As such, your wrapper would still offer added value on top of this interface. I hope you get around one day to upgrade the wrapper to support the newer version of pjsip.

Thank you for all the time you spend helping me.

siniypin commented 8 years ago

Hey Mark, good news.

I'd appreciate you sharing your SWIG bindings to pjsip, so anyone (including me) could simply adapt pjsip4net interface to pjsip 2.x.

Cheers

marknelissen commented 8 years ago

I've followed the instructions of MikeGawi on issue 15. Although pjsip natively only has the necessary configurations for java and python, there is only minor adaptation to be done of the generated files.

I only discovered the project at https://github.com/StrikeForceZero/PJSip-CSharp after having done all the work. I don't know how far along it is, and whether it works.

marknelissen commented 8 years ago

pjsua2api.zip contains the swig bindings I used. The documentation at www.pjsip.org/docs/book-latest/html/index.html is rather helpful on how to use the api, even though you have to translate the example code from c++ to c#.

siniypin commented 8 years ago

Awesome, Mark. Thank you very much! ᐧ

Best regards, Boris Tveritnev de.linkedin.com/pub/boris-tveritnev/11/3a4/113/ www.xing.com/profile/Boris_Tveritnev

On 16 March 2016 at 12:53, marknelissen notifications@github.com wrote:

pjsua2api.zip https://github.com/siniypin/pjsip4net/files/175879/pjsua2api.zip contains the swig bindings I used. The documentation at www.pjsip.org/docs/book-latest/html/index.html is rather helpful on how to use the api, even though you have to translate the example code from c++ to c#.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/siniypin/pjsip4net/issues/43#issuecomment-197281369