Click here to Skip to main content
Click here to Skip to main content
Go to top

SIP Stack with SIP Proxy - (VOIP)

, 11 Jun 2007
Rate this:
Please Sign up or sign in to vote.
C# implementation of SIP
Screenshot - proxy.jpg

SIP Overview

SIP is an application-layer control protocol that can establish, modify, and terminate multimedia sessions (conferences) such as Internet telephony calls. SIP can also invite participants to already existing sessions, such as multicast conferences. Normally SIP uses UDP and TCP port 5060 and TCP 5061 for SSL communication. SIP protocol is very similar to HTTP, so if you have some knowledge about HTTP, then it is easy to learn SIP. SIP doesn't transfer session data like audio, video. RTP(real time protocol) is used for that, SIP just helps to open RTP streams.

SIP Message Example

INVITE sip:john@domain.com SIP/2.0
From: <sip:doe@domain.com>;tag=2084442460
To: <sip:john@1domain.com>
Via: SIP/2.0/UDP domain.com:5060;branch=z9hG4bK2df7b9194cd51e25
Call-ID: john@domain.com-4524j
CSeq: 1 INVITE
Contact: <sip:doe@domain.com:5060>
Content-Length: 226
Content-Type: application/sdp

<session description data, like RTP description>

SIP Server Types

stateless SIP server doesn't store any transaction info.
statefull SIP server creates and holds SIP commands transaction state.
registrar/location Allows users to register their locations and later to use that info to forward calls to registered contact.
B2BUA SIP server is like statefull + holds active calls state.(This is needed if call billing or full control of call is needed)
presence Provides user availability services, like if user is online,offline, ... .
... There are some more, but not so important ones.

Basic SIP Commands

  • INVITE - Initiates a session. This method includes information about the calling and called users and the type of media that is to be exchanged.
  • ACK - Sent by the client who sends the INVITE. ACK is sent to confirm that the session is established. Media can then be exchanged.
  • BYE - Terminates a session. This method can be sent by either user.
  • CANCEL - Terminates a pending request, such as an outstanding INVITE. After a session is established, a BYE method needs to be used to terminate the session.
  • OPTIONS - Queries the capabilities of the server or other devices. It can be used to check media capabilities before issuing an INVITE.
  • REGISTER - Used by a client to login and register its address with a SIP registrar server.

Ok, some ABC done, there are many documents on the internet, so it is not a good idea to rewrite these there.

If want more advanced information, then see:

SIP Proxy Demo Overview

This SIP proxy example just implements fully functional simple stateless, statefull, b2bua proxy. You can use hardware SIP phones or soft phones to play with this proxy.This is an advanced example, code is well commented, so beginners don't hate me because no more text here. Just read RFC 3216, see information links I noted earlier. After you go through those, if you then look at the code, it is all nicer then.

Some free available softphones are:

Version:
    11.06.2007
        *) Added B2BUA support.
    07.04.2007 
        *) Many bug fixes. 
        *) SIP -> PSTN and PSTN -> SIP gateway support. 
        *) Non-SIP URI gateway support. 

Contact Details

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ivar Lumi

Estonia Estonia
No Biography provided

Comments and Discussions

 
QuestionGetting 403 Forbidden error PinmemberShishir Shetty13-Feb-14 5:12 
GeneralMy vote of 3 PinmemberMic6-Aug-13 14:26 
Questionstudy sip Pinmemberape1236-Apr-13 0:02 
Questioncalling bug Pinmembershadi2421-Nov-12 23:22 
Bugzero?o? [modified] PinmemberMember 883330021-Jun-12 16:43 
Bugbug PinmemberMember 883330017-Jun-12 0:46 
GeneralRe: bug PinmemberIvar Lumi17-Jun-12 22:05 
QuestionHow to Register IP Phone ??? Pinmemberkelibox23-Aug-11 1:04 
AnswerRe: How to Register IP Phone ??? PinmemberIvar Lumi23-Aug-11 1:07 
GeneralRe: How to Register IP Phone ??? Pinmemberkelibox24-Aug-11 3:56 
Finally I set the Registrar as URL, than Register process is successful.
IP Phone : IP: 192.168.1.2, UserName: 101, Account: 101, PassWord:1234 , SIP Proxy: 192.168.1.253, Registrar: test.com
SIP Proxy: Setting Tab -> IP: 192.168.1.253, User Account: 101, PassWord:1234 , Address: 101@test.com
///////////////
But new problem happen. After the Communication between two IP Phones and the sip flows disposed, I redial a phone but get a error message as following:
=========error log======================================
System.ObjectDisposedException: Fail to access the Disposed object 。
object name: 'SIP_Flow'。
於 LumiSoft.Net.SIP.Stack.SIP_Flow.get_ID() 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Stack\SIP_Flow.cs: 行 477
於 LumiSoft.Net.SIP.Proxy.SIP_ProxyContext.TargetHandler.SendToFlow(SIP_Flow flow, SIP_Request request) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Proxy\SIP_ProxyContext.cs: 行 615
於 LumiSoft.Net.SIP.Proxy.SIP_ProxyContext.TargetHandler.Start() 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Proxy\SIP_ProxyContext.cs: 行 532
於 LumiSoft.Net.SIP.Proxy.SIP_ProxyContext.Start() 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Proxy\SIP_ProxyContext.cs: 行 1025
於 LumiSoft.Net.SIP.Proxy.SIP_Proxy.ForwardRequest(Boolean statefull, SIP_RequestReceivedEventArgs e, Boolean addRecordRoute) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Proxy\SIP_Proxy.cs: 行 587
於 LumiSoft.Net.SIP.Proxy.SIP_Proxy.OnRequestReceived(SIP_RequestReceivedEventArgs e) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Proxy\SIP_Proxy.cs: 行 174
===========sip log=============================
Transaction [branch='z9hG4bK0b3458bd91bbc9dbac04f955c639d475';method='BYE';IsServer=True] switched to 'Completed' state.
Transaction [branch='z9hG4bK0b3458bd91bbc9dbac04f955c639d475';method='BYE';IsServer=true] timer J(Non-INVITE request retransmission wait) started, will trigger after 32000.
Transaction [branch='z9hG4bK-75d6c012c1be4f818bf8a145592ddeee';method='BYE';IsServer=False] switched to 'Completed' state.
Transaction [branch='z9hG4bK-75d6c012c1be4f818bf8a145592ddeee';method='BYE';IsServer=false] timer K(Non-INVITE 3xx - 6xx response retransmission wait) started, will trigger after 5000.
Transaction [branch='z9hG4bK-75d6c012c1be4f818bf8a145592ddeee';method='BYE';IsServer=false] timer K(Non-INVITE 3xx - 6xx response retransmission wait) triggered.
Transaction [branch='z9hG4bK-75d6c012c1be4f818bf8a145592ddeee';method='BYE';IsServer=False] switched to 'Terminated' state.
Transaction [branch='z9hG4bK-75d6c012c1be4f818bf8a145592ddeee';method='BYE';IsServer=false] disposed.
Transaction [branch='z9hG4bK-75d6c012c1be4f818bf8a145592ddeee';method='BYE';IsServer=False] switched to 'Disposed' state.
ProxyContext(id='c4251e80-8ba0-40bb-b172-97f8980427fa') disposed.
Request [method='INVITE'; cseq='8'; transport='UDP'; size='780'; received '192.168.1.2:5060' -> '192.168.1.253:5060'.
 
INVITE sip:103@test2.com SIP/2.0
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,PRACK,REFER,UPDATE
Call-ID: 4190661699-2B8D-0006
Contact: "102"
Content-Type: application/sdp
CSeq: 8 INVITE
Expires: 180
From: "102" ;tag=40-1766746275
Max-Forwards: 70
Supported: replaces,timer
To:
User-Agent: AmRoad
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bK3e67bd1a77d7ca7954d700aceac28d13;received=192.168.1.2
Content-Length: 263
 
v=0
o=102 4190661697 4190661697 IN IP4 192.168.1.2
s=Session SDP
c=IN IP4 192.168.1.2
t=0 0
m=audio 9016 RTP/AVP 18 0 8 101
a=ptime:20
a=rtpmap:18 G729/8000
a=rtpmapBlush | :O PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000/1
a=fmtp:101 0-15
 
Transaction [branch='z9hG4bK3e67bd1a77d7ca7954d700aceac28d13';method='INVITE';IsServer=true] created.
Transaction [branch='z9hG4bK3e67bd1a77d7ca7954d700aceac28d13';method='INVITE';IsServer=True] switched to 'Proceeding' state.
ProxyContext(id='5b232fdc-fdae-4828-a96a-e771034269e4') created.
Response [transactionID=''; method='INVITE'; cseq='8'; transport='UDP'; size='423'; statusCode='500'; reason='Server Internal Error: Fail to access the Disposed object。
object name: 'SIP_Flow'。'; sent '' -> '192.168.1.2:5060'.
 
SIP/2.0 500 Server Internal Error:
object name: 'SIP_Flow'
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bK3e67bd1a77d7ca7954d700aceac28d13;received=192.168.1.2
From: "102" ;tag=40-1766746275
To: ;tag=a18f4a78a3a52b0e8ff37026
Call-ID: 4190661699-2B8D-0006
CSeq: 8 INVITE
Allow: INVITE,ACK,CANCEL,BYE,MESSAGE
Content-Length: 0
 

Request [transactionID='z9hG4bK3e67bd1a77d7ca7954d700aceac28d13'; method='ACK'; cseq='8'; transport='UDP'; size='332'; received '192.168.1.253:5060' <- '192.168.1.2:5060'.
 
ACK sip:103@test2.com SIP/2.0
Call-ID: 4190661699-2B8D-0006
CSeq: 8 ACK
From: "102" ;tag=40-1766746275
Max-Forwards: 70
To: ;tag=a18f4a78a3a52b0e8ff37026
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bK3e67bd1a77d7ca7954d700aceac28d13;received=192.168.1.2
Content-Length: 0
 

Response [flowReuse=true; transactionID='z9hG4bK3e67bd1a77d7ca7954d700aceac28d13'; method='INVITE'; cseq='8'; transport='UDP'; size='344'; statusCode='100'; reason='Trying'; sent '192.168.1.253:5060' -> '192.168.1.2:5060'.
 
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bK3e67bd1a77d7ca7954d700aceac28d13;received=192.168.1.2
From: "102" ;tag=40-1766746275
To: ;tag=a18f4a78a3a52b0e8ff37026
Call-ID: 4190661699-2B8D-0006
CSeq: 8 INVITE
Allow: INVITE,ACK,CANCEL,BYE,MESSAGE
Content-Length: 0
 

Transaction [branch='z9hG4bK0b3458bd91bbc9dbac04f955c639d475';method='BYE';IsServer=true] timer I(Non-INVITE request retransmission wait) triggered.
Transaction [branch='z9hG4bK0b3458bd91bbc9dbac04f955c639d475';method='BYE';IsServer=True] switched to 'Terminated' state.
GeneralRe: How to Register IP Phone ??? PinmemberIvar Lumi24-Aug-11 4:15 
GeneralRe: How to Register IP Phone ??? Pinmemberkelibox25-Aug-11 13:26 
QuestionHow to set enviroenment Pinmemberbliznak220-Jul-11 3:31 
AnswerRe: How to set enviroenment PinmemberIvar Lumi20-Jul-11 19:11 
Generalvoip sip client with video Pinmemberwaelsys200724-May-11 1:33 
GeneralRe: voip sip client with video PinmemberIvar Lumi24-May-11 2:41 
GeneralA question about RTCP Pinmemberywchen8-Apr-11 15:17 
GeneralRe: A question about RTCP PinmemberIvar Lumi8-Apr-11 20:10 
GeneralRe: A question about RTCP Pinmemberywchen12-Apr-11 12:58 
GeneralRe: A question about RTCP PinmemberIvar Lumi12-Apr-11 19:01 
GeneralSIP_Authenticate AuthContext cannot get the password of the client application PinmemberSing52012-Mar-11 18:07 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application PinmemberIvar Lumi2-Mar-11 19:12 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application PinmemberSing52012-Mar-11 19:15 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application PinmemberIvar Lumi2-Mar-11 19:17 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application PinmemberSing52012-Mar-11 19:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 11 Jun 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid