I have set the IP address for the two emulator instance , On ubuntu
terminal I input "netstat -an|grep 5060/5061"
and it shows
"tcp 0 0 127.0.0.1:5060/5061 0.0.0.0:*
LISTEN" , and input "" ;
and I redirect the emulator's adress to my localhost adress by using
commands "redir add tcp:5061:5061 " and "redir add tcp:5060:5060 " .
then I run my sip application ,the UAS(server) could listening on port
5060 , and the USC(client) could listening on port 5061 too. but the
client can not send a INVITE successfully !
I still doubt the IP adress and port were not set correctly , because
"eXosip_init" and "eXosip_listen_addr " were successful, there was no
other mistakes.
here is the Native codes ,it includes a UAS and a UAC ,providing two
interface in JNI form just like:
public native int startServer();
public native int startClent();
Native codes for UAS/USC:
include <eXosip2/eXosip.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <osip2/osip_mt.h>
#include <android/log.h>
#include <jni.h>
#include <unistd.h>
#include <sys/mman.h>
#include <assert.h>
#include <limits.h>
#include <unistd.h>
#define UA_TAG "Test eXosip ==============================TAG"
jint Java_com_android_sip_JniCross_startServer()
{
eXosip_event_t *je = NULL;
osip_message_t *ack = NULL;
osip_message_t *invite = NULL;
osip_message_t *answer = NULL;
sdp_message_t *remote_sdp = NULL;
int call_id, dialog_id;
int i,j;
int id;
char command;
char tmp[4096];
char localip[128];
int pos = 0;
i = eXosip_init ();
if (i != 0)
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"Can't initialize
eXosip!\n");
return -1;
}
else
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"eXosip_init
successfully!\n");
}
i = eXosip_listen_addr (IPPROTO_TCP, NULL, 5061, AF_INET, 0);
if (i != 0)
{
eXosip_quit ();
__android_log_print(ANDROID_LOG_INFO, UA_TAG, "eXosip_listen_addr
error!\nCouldn't initialize transport layer\n");
}
for(;;)
{
je = eXosip_event_wait (0,50);
eXosip_lock ();
eXosip_default_action (je);
eXosip_automatic_refresh ();
eXosip_unlock ();
if (je == NULL)
continue;
// __android_log_print(ANDROID_LOG_INFO, UA_TAG,"the cid is %s,
did is %s\n", je->did, je->cid);
switch (je->type)
{
case EXOSIP_MESSAGE_NEW:
__android_log_print(ANDROID_LOG_INFO, UA_TAG, "UA_TAG,
EXOSIP_MESSAGE_NEW!\n");
if (MSG_IS_MESSAGE (je->request))
{
{
osip_body_t *body;
osip_message_get_body (je->request, 0, &body);
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"I get
the msg is: %s\n", body->body);
//__android_log_print(ANDROID_LOG_INFO, UA_TAG,"the
cid is %s, did is %s\n", je->did, je->cid);
}
eXosip_message_build_answer (je->tid, 200,&answer);
eXosip_message_send_answer (je->tid, 200,answer);
}
break;
case EXOSIP_CALL_INVITE:
__android_log_print(ANDROID_LOG_INFO, UA_TAG,
"Received a INVITE msg from %s:%s, UserName is
%s,password is %s\n",
je->request->req_uri->host,
je->request->req_uri->port,
je->request->req_uri->username,
je->request->req_uri->password);
remote_sdp = eXosip_get_remote_sdp (je->did);
call_id = je->cid;
dialog_id = je->did;
eXosip_lock ();
eXosip_call_send_answer (je->tid, 180, NULL);
i = eXosip_call_build_answer (je->tid, 200, &answer);
if (i != 0)
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"This
request msg is invalid!Cann't response!\n");
eXosip_call_send_answer (je->tid, 400, NULL);
}
else
{
snprintf (tmp, 4096,
"v=0\r\n"
"o=anonymous 0 0 IN IP4 0.0.0.0\r\n"
"t=1 10\r\n"
"a=username:xuanjt\r\n"
"a=password:uvwxyZ198358\r\n");
osip_message_set_body (answer, tmp, strlen(tmp));
osip_message_set_content_type (answer,
"application/sdp");
eXosip_call_send_answer (je->tid, 200, answer);
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"send 200
over!\n");
}
eXosip_unlock ();
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"the INFO is
:\n");
while (!osip_list_eol (&remote_sdp->a_attributes, pos))
{
sdp_attribute_t *at;
at = (sdp_attribute_t *) osip_list_get
(&remote_sdp->a_attributes, pos);
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"%s :
%s\n", at->a_att_field, at->a_att_value);
pos ++;
}
break;
case EXOSIP_CALL_ACK:
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"ACK
recieved!\n");
// __android_log_print(ANDROID_LOG_INFO, UA_TAG,"the cid is
%s, did is %s\n", je->did, je->cid);
break;
case EXOSIP_CALL_CLOSED:
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"the remote
hold the session!\n");
// eXosip_call_build_ack(dialog_id, &ack);
//eXosip_call_send_ack(dialog_id, ack);
i = eXosip_call_build_answer (je->tid, 200, &answer);
if (i != 0)
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,
"This request msg is invalid!Cann't response!\n");
eXosip_call_send_answer (je->tid, 400, NULL);
}
else
{
eXosip_call_send_answer (je->tid, 200, answer);
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"bye send
200 over!\n");
}
break;
case EXOSIP_CALL_MESSAGE_NEW:
/*
/* request related events within calls (except INVITE) */
// EXOSIP_CALL_MESSAGE_NEW, /**< announce new
incoming request. */
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"
EXOSIP_CALL_MESSAGE_NEW\n");
if (MSG_IS_INFO(je->request))
{
eXosip_lock ();
i = eXosip_call_build_answer (je->tid, 200, &answer);
if (i == 0)
{
eXosip_call_send_answer (je->tid, 200, answer);
}
eXosip_unlock ();
{
osip_body_t *body;
osip_message_get_body (je->request, 0, &body);
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"the
body is %s\n", body->body);
}
}
break;
default:
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"Could not parse
the msg!\n");
break;
}//end switch
}//end for
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
jint Java_com_android_sip_JniCross_startClent()
{
eXosip_event_t *je;
osip_message_t *reg = NULL;
osip_message_t *invite = NULL;
osip_message_t *ack = NULL;
osip_message_t *info = NULL;
osip_message_t *message = NULL;
int ire = 0;
int call_id, dialog_id;
int i,flag;
int flag1 = 1;
int id;
char *source_call = "sip:[email protected] <sip%[email protected]>";
char *dest_call = "sip:[email protected]:5061";
char command = 'i';
char tmp[4096];
char localip[128];
i = eXosip_init ();
if (i != 0)
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"Couldn't initialize
eXosip!\n");
return -1;
}
else
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"eXosip_init
successfully!\n");
}
i = eXosip_listen_addr (IPPROTO_TCP, NULL, 5060, AF_INET, 0);
if (i != 0)
{
eXosip_quit ();
__android_log_print(ANDROID_LOG_INFO, UA_TAG, "Couldn't initialize
transport layer!\n");
return -1;
}
flag = 1;
while (flag)
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"please input the
comand:\n");
//scanf ("%c", &command);
//getchar ();
switch (command)
{
case 'r':
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"This modal
isn't commpleted!\n");
break;
case 'i':/* INVITE */
i = eXosip_call_build_initial_invite (&invite, dest_call,
source_call, NULL, "This si a call for a conversation");
if (i != 0)
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"Intial
INVITE failed!\n");
break;
}else
{
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"Intial
INVITE sucessfully!\n");
}
snprintf (tmp, 4096,
"v=0\r\n"
"o=anonymous 0 0 IN IP4 0.0.0.0\r\n"
"t=1 10\r\n"
"a=username:xuanjt\r\n"
"a=password:uvwxyZ198358\r\n");
osip_message_set_body (invite, tmp, strlen(tmp));
osip_message_set_content_type (invite, "application/sdp");
eXosip_lock ();
i = eXosip_call_send_initial_invite (invite);
eXosip_unlock ();
flag1 = 1;
while (flag1)
{
je = eXosip_event_wait (0, 200);
if (je == NULL)
{
ire = 10222;
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"No
response or the time is over!\n");
break;
}
switch (je->type)
{
case EXOSIP_CALL_INVITE:
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"a
new invite reveived!\n");
break;
case EXOSIP_CALL_PROCEEDING:
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"proceeding!\n");
break;
case EXOSIP_CALL_RINGING:
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"ringing!\n");
// call_id = je->cid;
// dialog_id = je->did;
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"call_id is %d, dialog_id is %d \n", je->cid, je->did);
break;
case EXOSIP_CALL_ANSWERED:
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"ok! connected!\n");
call_id = je->cid;
dialog_id = je->did;
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"call_id is %d, dialog_id is %d \n", je->cid, je->did);
eXosip_call_build_ack (je->did, &ack);
eXosip_call_send_ack (je->did, ack);
flag1 = 0;
ire = 1001;
break;
case EXOSIP_CALL_CLOSED:
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"the other sid closed!\n");
break;
case EXOSIP_CALL_ACK:
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"ACK received!\n");
break;
default:
ire = 1000;
__android_log_print(ANDROID_LOG_INFO,
UA_TAG,"other response!\n");
break;
}
eXosip_event_free (je);
}//end while flag1
break;
case 'h':
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"Holded !\n");
eXosip_lock ();
eXosip_call_terminate (call_id, dialog_id);
eXosip_unlock ();
break;
case 'c':
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"This modal
isn't commpleted!\n");
break;
case 's':
eXosip_call_build_info (dialog_id, &info);
snprintf (tmp , 4096,"hello,rainfish");
osip_message_set_body (info, tmp, strlen(tmp));
osip_message_set_content_type (info, "text/plain");
eXosip_call_send_request (dialog_id, info);
break;
case 'm'
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"the mothed
:MESSAGE\n");
eXosip_message_build_request (&message, "MESSAGE",
dest_call, source_call, NULL);
snprintf (tmp, 4096,"hellor xuanjt");
osip_message_set_body (message, tmp, strlen(tmp));
osip_message_set_content_type (message, "text/xml");
eXosip_message_send_request (message);
break;
case 'q':
eXosip_quit();
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"Exit the
setup!\n");
flag = 0;
break;
}//end switch (command)
}//end while flag
return ire;
}
the above two interface which were built in "ua.so" , can be called
successfully by java code.
the client will keeping looping at :
while (flag1)
{
je = eXosip_event_wait (0, 200);
if (je == NULL)
{
ire = 10222;
__android_log_print(ANDROID_LOG_INFO, UA_TAG,"No
response or the time is over!\n");
break;
}
...
...
}
the je always NULL, and it keeped looping!
any one can give any advices? thanks in advance!
2010/1/28 jotobjects <[email protected]>
> See this link about emulator IP address:
>
>
> http://developer.android.com/intl/fr/guide/developing/tools/emulator.html#networkaddresses
>
> And see this link about network redirecting:
>
>
> http://developer.android.com/intl/fr/guide/developing/tools/emulator.html#redirections
>
> Thanks for sharing this information and please keep us up to date. I
> looked at the Jain SIP stack which looks very promising except that it
> is too large to be practical for an Android application. The other
> practical issue about using SIP is that the IP address of the device
> can change which is a problem for push (like SIP Notify messages).
>
> On Jan 27, 12:12 am, Tony <[email protected]> wrote:
> > Hello ,All!
> >
> > I'd like to share my sip development experience with you as well giving
> > you my problems.I hope anyone can help me!
> >
> > I compiled osipperser2 ,osip2 and exosip2 on NDK platform, Base on
> the
> > three static libraries osipperser.a ,osip2.a ,exosip2.a , I wrote a
> sample
> > base on sip and it was compiled to share library, it include a
> > server(UAC) and a client (UAC), now I can load the sample so
> successfully
> > and made both of them running on two emulator instances, but I didn't
> how
> > to set the SIP UIRs , I don't know the two emulators' IP address, How
> can
> > the two emulator instances communicate with each other by SIP.????
> >
> > is 10.0.02 or 10.0.0.15 the emulator's IP????
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
I have a strong desire to become to a android superior; let us work hard
together!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en