Android Tutorial Android Sip / Voip tutorial

kahvesoft

New Member
Licensed User
Longtime User
I wanted to test the SIP application. error given by the register while

Failed, errorCode = -9, Message = 0



I'm using the mini sip server. They're also not be a problem for another client registers

I used part of the register

Sip.ınitialize2 ("SIP", "sip: 102@192.168.2.122", "102")
sip.regist is

What could be the problem.


mini sip server debug:

2014-11-08 17:34:53 | Recv SIP-UDP message address=192.168.2.69, port=58119 (len=375):
REGISTER sip:192.168.2.122 SIP/2.0
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
CSeq: 2078 REGISTER
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: *
Expires: 0
Content-Length: 0


2014-11-08 17:34:53 | sip_reg_fac[000003F5] _procRegister
2014-11-08 17:34:53 | sip_reg_fac[000003F5] oCheckAuthRegister
2014-11-08 17:34:53 | sip_reg_fac[000003F5] receive message from 192.168.2.69:58119 :
2014-11-08 17:34:53 | sip_reg_fac[000003F5] REGISTER sip:192.168.2.122
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
CSeq: 2078 REGISTER
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: *
Expires: 0
Content-Length: 0


2014-11-08 17:34:53 | Send SIP-UDP message to (ip=192.168.2.69, port=58119):
2014-11-08 17:34:53 | SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;received=192.168.2.69;rport=58119
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>;tag=3752773d
CSeq: 2078 REGISTER
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE
User-Agent: miniSIPServer V17 (20 clients) build 20141105
Proxy-Authenticate: Digest realm="192.168.2.122",algorithm=MD5,nonce="3D00503133B3311B038A24F94C667123",stale=FALSE
Content-Length: 0


2014-11-08 17:34:53 | sip_reg_fac[000003F5] fail to check authorization.
2014-11-08 17:34:53 | Recv SIP-UDP message address=192.168.2.69, port=58119 (len=375):
REGISTER sip:192.168.2.122 SIP/2.0
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
CSeq: 2078 REGISTER
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: *
Expires: 0
Content-Length: 0


2014-11-08 17:34:53 | sip_reg_fac[000003F5] _procRegister
2014-11-08 17:34:53 | sip_reg_fac[000003F5] oCheckAuthRegister
2014-11-08 17:34:53 | sip_reg_fac[000003F5] receive message from 192.168.2.69:58119 :
2014-11-08 17:34:53 | sip_reg_fac[000003F5] REGISTER sip:192.168.2.122
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
CSeq: 2078 REGISTER
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: *
Expires: 0
Content-Length: 0


2014-11-08 17:34:53 | Send SIP-UDP message to (ip=192.168.2.69, port=58119):
2014-11-08 17:34:53 | SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;received=192.168.2.69;rport=58119
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>;tag=3106443e
CSeq: 2078 REGISTER
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE
User-Agent: miniSIPServer V17 (20 clients) build 20141105
Proxy-Authenticate: Digest realm="192.168.2.122",algorithm=MD5,nonce="3D00503133B3311B038A24F94C667123",stale=FALSE
Content-Length: 0


2014-11-08 17:34:53 | sip_reg_fac[000003F5] fail to check authorization.
2014-11-08 17:34:54 | Recv SIP-UDP message address=192.168.2.69, port=58119 (len=375):
REGISTER sip:192.168.2.122 SIP/2.0
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
CSeq: 2078 REGISTER
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: *
Expires: 0
Content-Length: 0


2014-11-08 17:34:54 | sip_reg_fac[000003F5] _procRegister
2014-11-08 17:34:54 | sip_reg_fac[000003F5] oCheckAuthRegister
2014-11-08 17:34:54 | sip_reg_fac[000003F5] receive message from 192.168.2.69:58119 :
2014-11-08 17:34:54 | sip_reg_fac[000003F5] REGISTER sip:192.168.2.122
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
CSeq: 2078 REGISTER
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;rport
Max-Forwards: 70
User-Agent: SIPAUA/0.1.001
Contact: *
Expires: 0
Content-Length: 0


2014-11-08 17:34:54 | Send SIP-UDP message to (ip=192.168.2.69, port=58119):
2014-11-08 17:34:54 | SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP 192.168.2.69:58119;branch=z9hG4bK22bb265f955d4d733eeeadac943bc5e7353539;received=192.168.2.69;rport=58119
From: <sip:102@192.168.2.122>;tag=2683354394
To: <sip:102@192.168.2.122>;tag=014b7cb4
CSeq: 2078 REGISTER
Call-ID: 1ac2720e2f410be211ab2701868d2466@192.168.2.69
Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, REFER, SUBSCRIBE
User-Agent: miniSIPServer V17 (20 clients) build 20141105
Proxy-Authenticate: Digest realm="192.168.2.122",algorithm=MD5,nonce="3D00503133B3311B038A24F94C667123",stale=FALSE
Content-Length: 0


2014-11-08 17:34:54 | sip_reg_fac[000003F5] fail to check authorization.
 

kahvesoft

New Member
Licensed User
Longtime User
I made a mistake when typing the following line here already.

Sip.Initialize2("SIP", "sip:102@192.168.2.122", "102")
 

kahvesoft

New Member
Licensed User
Longtime User
7 different android sip-voip same server or even PC-based software works even in the voip software and autorized. There's something wrong about this. And password and username correct. Tested.
 

spacebuddy

Member
Licensed User
Longtime User
I get undeclared variable 'sip'. I checked the Sip checkbox under libraries. Anyone know why this is happening?
 

spacebuddy

Member
Licensed User
Longtime User
Thank you that really helped. I now get different error

java.lang.NullPointerException

on this line of code
Sip.Register
 

spacebuddy

Member
Licensed User
Longtime User
Here it is

Installing file.
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:anywheresoftware.b4a.samples.sip
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
Error occurred on line: 31 (main)
java.lang.NullPointerException
at android.net.sip.SipManager.open(SipManager.java:224)
at anywheresoftware.b4a.objects.SIP.Register(SIP.java:169)
at anywheresoftware.b4a.samples.sip.main._activity_create(main.java:346)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.samples.sip.main.afterFirstLayout(main.java:98)
at anywheresoftware.b4a.samples.sip.main.access$100(main.java:16)
at anywheresoftware.b4a.samples.sip.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4697)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
** Activity (main) Resume **
 

spacebuddy

Member
Licensed User
Longtime User
I just tried it on a Motorola Moto G and it works.

I get a lot of echo, not very good quality but it works.
 

billyn_hk

Member
Licensed User
Longtime User
We have just try the sip sample, and tested with 2 sip providers, iptel.org and sip2sip.info
the registering process is not stable testing on Samsung S4 and some other android 4.4 phones.

mostly we get:
error code -10, err msg: no data connection
error code -9, err msg:0

we only able to get successful registration with the Sip.Initialize some of the time, and totally not able to connect with with Sip.Initialize2 , wondering whats the different that may causing this ?

1 out of 30~50 tried, that we may get success registration.
upon successful registration, we were able to make calls from sip1 to sip2 and both party can talk without problem. so the problem lies on the initial connection ... ?

and for success registration, we observe, the event: Registering fire up again after the event: registerationDone. (i.e. the Registering event fires up 2 times.)

any clue of this unstable registration ? or is there any other prequestite environment required ?

1. B4A4.0 -> tools -> configure Path -> android.jar
C:\Program Files\Android\android-sdk\platforms\android-15\android.jar

2.
manifest used:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="14" />
  <uses-permission android:name="android.permission.USE_SIP" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.VIBRATE" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />  
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <uses-feature android:name="android.hardware.sip.voip" android:required="true" />
  <uses-feature android:name="android.hardware.wifi" android:required="true" />
  <uses-feature android:name="android.hardware.microphone" android:required="true" />  
<supports-screens android:largeScreens="true"
  android:normalScreens="true"
  android:smallScreens="true"
  android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

We try to download Play market sip client, most of them works without problem.
So if we were to develop apps using sip voip, was B4A a good start point ?

if anybody happen to smoothly using this sip library , please shed a light , we are more than happy to offer credit and donations to have this solved.

thanks in advance
 
Last edited:

billyn_hk

Member
Licensed User
Longtime User
This library uses the native SIP features. There are other apps that implement the SIP protocol themselves.

I tested it on several devices (mostly Nexus devices) and didn't encounter such issues.


Thanks Erel for the update. We understand it is not related to B4A.

however, when ppl seeing B4A advertising shows Sip/VoIP as new feature, they might doubt it when they experience unstable issues. Even the SipPhone demo does fail in China phones.

was it possible for us to use this http://www.portsip.com/voipsdk.html inside B4A ?
could you advise how to include this.

Was there anyone whom using B4A and implement their own SIP protocol, we are willing to pay for the code.
Please let us know. thanks