< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index  

Re: [reSIProcate-users] How to code this simple SIP session?


Hi Vijay,

>From my personal experience with reSIProcate, I would give it a shot
using the resip Dialog Usage Manager (or "dum"). It is a higher level
API that
hides some of the complexities related to directly using the stack.

Using the dum, you define objects that implement the behavior you want
to handle. In your case, you want to send an INVITE dialog (as a
client) and then receive a SUBSCRIBE one (as a server). The handlers
that you would need to use with the dum would be InviteSessionHandler
and ServerSubscriptionHandler.

Keep in mind that the dum doesn't do everything for you: it will let
your handlers know when something happens but you will need to react
to them yourself.

Look at resip/dum/test/BasicCall.cxx, it gives an example using the
InviteSessionHandler.


Hope this helps,
Francis

On Mon, Apr 12, 2010 at 7:46 AM, Vijay Mathew
<vijay.the.schemer@xxxxxxxxx> wrote:
> Hi Scott,
>
> Thanks for the response. I tried the steps suggested by you, to no
> avail. About reading the RFC, libraries like reSIProcate exist because
> lazy people like me could be saved from such drudgery :-). What I am
> looking for is a sequence of API calls (just the function calls, not
> the entire code) to manage the scenario I described in my earlier
> mail. For instance, if I am using an HTTP wrapper, I expect to see
> something like this, somewhere in the docs:
>
> HttpClient client (host, port);
> client.request ("index.html");
> client.close ();
>
> Is there something similar for reSIProcate? It will be really useful
> if the docs show how to achieve simple tasks like this.
>
> best regards,
>
> -- Vijay
>
> On Fri, Apr 9, 2010 at 7:39 PM, Scott Godin <sgodin@xxxxxxxxxxxxxxx> wrote:
>> Seems like a good read through of RFC3261 would be good to get a better
>> understanding how to form valid SIP messages and responses.  There are also
>> code samples throughout resip that will help - see dum/Helper.cxx and
>> stack/DeprecatedDialog.cxx.
>> A couple of things I see quickly:
>> 1.  The CSEQ in the ACK should match the invite.
>> 2.  The ACK/200 message should be routed to the Contact header received in
>> the 200.  If the destination is not receiving the ACK or it is malformed,
>>  they will retransmit the 200.
>> 3.  You don't need to populate the via header - the stack will do this for
>> you as long as you add an empty via header:  see Helper::makeRequest for a
>> good sample.  Similar rules apply to the Contact header - you only need to
>> add a empty contact header with the user field only populated - the stack
>> will fill in the rest.
>> Scott
>>
>> On Fri, Apr 9, 2010 at 8:50 AM, Vijay Mathew <vijay.the.schemer@xxxxxxxxx>
>> wrote:
>>>
>>> Hi all,
>>>
>>> I want to create a simple SIP client that will do the following
>>> interactions with an existing SIP server:
>>>
>>> client                                    server
>>>
>>> INVITE   ============>
>>>             <===========      200 OK
>>> ACK      ============>
>>>             <============   SUBSCRIBE
>>> 200 OK  =============>
>>> NOTIFY  =============>
>>>            <=============   200 OK
>>> BYE     ==============>
>>>           <==============  200 OK
>>>
>>> I tried the following code to start with the INVITE and the ACK. I get
>>> "200 OK" for the INVITE but for the ACK, I am again getting the same
>>> "200 OK" that I got for the INVITE. What did I do wrong?
>>>
>>> static SipMessage* receive(SipStack& tu)
>>> {
>>>        while (true)
>>>        {
>>>                Sleep(100);
>>>                SipMessage *msg = stack.receive();
>>>                if (msg)
>>>                {
>>>                        std::cout << *msg << '\n';
>>>                        return msg;
>>>                }
>>>        }
>>>        return 0;
>>> }
>>>
>>> int
>>> main ()
>>> {
>>>    NameAddr target;
>>>    target.uri().scheme() = "sip";
>>>    target.uri().host() = "192.168.114.211";
>>>    target.uri().port() = 5060;
>>>    target.uri().param(p_transport) = "tcp";
>>>
>>>    NameAddr from = target;
>>>    from.uri().user() = "me";
>>>    from.uri().port() = 5070;
>>>
>>>    std::auto_ptr<SipMessage> reg(Helper::makeInvite(target, from));
>>>
>>>    reg->header(h_Contacts).clear();
>>>    reg->header(h_Contacts).push_back(from);
>>>    reg->header(h_Vias).front().transport() = Data("tcp");
>>>    reg->header(h_Vias).front().sentHost() = "192.168.114.211";
>>>    reg->header(h_Vias).front().sentPort() = 5070;
>>>        Tokens tokens;
>>>        tokens.push_back(Token(Data("x-com-nice-imm-call-state")));
>>>        reg->header(h_AllowEvents) = tokens;
>>>
>>>        std::cout << *reg << '\n';
>>>
>>>        SipStack stack;
>>>        stack.addTransport(TCP, 5070);
>>>        StackThread stackThread(stack);
>>>        stackThread.run();
>>>        stack.send(*reg);
>>>
>>>        SipMessage* msg = receive(stack);
>>>        if (msg)
>>>        {
>>>                if (msg->isResponse())
>>>                {
>>>                        std::cout << "REASON=" << msg->getReason() << "\n";
>>>                        std::auto_ptr<SipMessage>
>>> reg(Helper::makeRequest(target, from, ACK));
>>>                        reg->header(h_Contacts).clear();
>>>                        reg->header(h_Contacts).push_back(from);
>>>                        reg->header(h_Vias).front().transport() =
>>> Data("tcp");
>>>                        reg->header(h_Vias).front().sentHost() =
>>> "192.168.114.211";
>>>                        reg->header(h_Vias).front().sentPort() = 5070;
>>>                        reg->header(h_CallID) = msg->header(h_CallId);
>>>                        std::cout << *reg << '\n';
>>>                        delete msg;
>>>                        msg = 0;
>>>                        stack.send(*reg);
>>>                }
>>>                else
>>>                {
>>>                        std::cout << "MSG is not a response\n";
>>>                }
>>>        }
>>>
>>>        msg = receive(stack);
>>>        if (msg)
>>>        {
>>>                if (msg->isResponse())
>>>                {
>>>                        std::cout << "REASON=" << msg->getReason() << "\n";
>>>                        delete msg;
>>>                        // std::auto_ptr<SipMessage>
>>> reg(Helper::makeRequest(target, from, ACK));
>>>                }
>>>                else
>>>                {
>>>                        std::cout << "MSG is not a response\n";
>>>                }
>>>        }
>>>
>>>        return 0;
>>> }
>>>
>>> Thanks in advance,
>>>
>>> -- Vijay
>>> _______________________________________________
>>> resiprocate-users mailing list
>>> resiprocate-users@xxxxxxxxxxxxxxx
>>> List Archive: http://list.resiprocate.org/archive/resiprocate-users/
>>
>>
> _______________________________________________
> resiprocate-users mailing list
> resiprocate-users@xxxxxxxxxxxxxxx
> List Archive: http://list.resiprocate.org/archive/resiprocate-users/
>