Click here to Skip to main content
15,886,689 members
Articles / Programming Languages / C#
Article

SIP Stack with SIP Proxy - (VOIP)

Rate me:
Please Sign up or sign in to vote.
4.86/5 (45 votes)
11 Jun 2007CPOL2 min read 1.6M   28.1K   162   354
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

statelessSIP server doesn't store any transaction info.
statefullSIP 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.
B2BUASIP 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)


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: SIP Client Pin
Binni shah2-Oct-09 3:04
Binni shah2-Oct-09 3:04 
QuestionUDP to TCP UA Pin
rudacunhasilva24-Aug-09 6:34
rudacunhasilva24-Aug-09 6:34 
QuestionSIP TCP Pin
rudacunhasilva20-Aug-09 14:48
rudacunhasilva20-Aug-09 14:48 
QuestionSIP_Gateway Pin
rudacunhasilva18-Aug-09 10:15
rudacunhasilva18-Aug-09 10:15 
AnswerRe: SIP_Gateway Pin
Ivar Lumi18-Aug-09 19:36
Ivar Lumi18-Aug-09 19:36 
QuestionHow to run both SIP Proxy and a client in the same computer? Pin
kaiwnyt10-Jul-09 15:36
kaiwnyt10-Jul-09 15:36 
AnswerRe: How to run both SIP Proxy and a client in the same computer? Pin
Ivar Lumi12-Jul-09 20:25
Ivar Lumi12-Jul-09 20:25 
GeneralRe: How to run both SIP Proxy and a client in the same computer? Pin
kaiwnyt14-Jul-09 17:32
kaiwnyt14-Jul-09 17:32 
Thank your reply, Ivar.

I close window's firewall and antivirus software, but it doesn't work.

After I replace localhost(127.0.0.1) with actual IP(192.168.1.112), error occurs in X-lite:
Registration error 407 - Proxy Authentication required. Authentication failed.
SIP debug:
*****************************************************************************************************************
Request [method='REGISTER'; cseq='1'; transport='UDP'; size='561'; received '192.168.1.112:37788' -> '192.168.1.112:5060'.
<begin>
REGISTER sip:192.168.1.112 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:37788;branch=z9hG4bK-d8754z-fa6cb94e3d2ee844-1---d8754z-;rport=37788;received=192.168.1.112
Max-Forwards: 70
Contact: <sip:kaiwn@127.0.0.1:37788;rinstance=6fa201926d45caa5>
To: "kaiwn" <sip:kaiwn@192.168.1.112>
From: "kaiwn" <sip:kaiwn@192.168.1.112>;tag=f352ba6a
Call-ID: MWVjZWExYzI3NDI0NjFlZjAzYTIzMTZmNDhhNDdlMGM.
CSeq: 1 REGISTER
Expires: 3600
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY,MESSAGE,SUBSCRIBE,INFO
User-Agent: X-Lite release 1103d stamp 53117
Content-Length: 0

<end>
Transaction [branch='z9hG4bK-d8754z-fa6cb94e3d2ee844-1---d8754z-';method='REGISTER';IsServer=true] created.
Transaction [branch='z9hG4bK-d8754z-fa6cb94e3d2ee844-1---d8754z-';method='REGISTER';IsServer=True] switched to 'Trying' state.
Response [flowReuse=true; transactionID='z9hG4bK-d8754z-fa6cb94e3d2ee844-1---d8754z-'; method='REGISTER'; cseq='1'; transport='UDP'; size='537'; statusCode='407'; reason='Proxy Authentication Required'; sent '192.168.1.112:5060' -> '192.168.1.112:37788'.
<begin>
SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP 127.0.0.1:37788;branch=z9hG4bK-d8754z-fa6cb94e3d2ee844-1---d8754z-;rport=37788;received=192.168.1.112
From: "kaiwn" <sip:kaiwn@192.168.1.112>;tag=f352ba6a
To: "kaiwn" <sip:kaiwn@192.168.1.112>;tag=d64043f8812fe2a1eb7fe3ea
Call-ID: MWVjZWExYzI3NDI0NjFlZjAzYTIzMTZmNDhhNDdlMGM.
CSeq: 1 REGISTER
Allow: INVITE,ACK,CANCEL,BYE,MESSAGE
Proxy-Authenticate: digest realm="",nonce="c68b373754244ddebfe6170763732df6",opaque="f9905829986f45fc960e4e11fe81129c"
Content-Length: 0

<end>
Transaction [branch='z9hG4bK-d8754z-fa6cb94e3d2ee844-1---d8754z-';method='REGISTER';IsServer=True] switched to 'Completed' state.
Transaction [branch='z9hG4bK-d8754z-fa6cb94e3d2ee844-1---d8754z-';method='REGISTER';IsServer=true] timer J(Non-INVITE request retransmission wait) started, will trigger after 32000.
Request [method='REGISTER'; cseq='2'; transport='UDP'; size='785'; received '192.168.1.112:37788' -> '192.168.1.112:5060'.
<begin>
REGISTER sip:192.168.1.112 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:37788;branch=z9hG4bK-d8754z-3938bc3f86545228-1---d8754z-;rport=37788;received=192.168.1.112
Max-Forwards: 70
Contact: <sip:kaiwn@127.0.0.1:37788;rinstance=6fa201926d45caa5>
To: "kaiwn" <sip:kaiwn@192.168.1.112>
From: "kaiwn" <sip:kaiwn@192.168.1.112>;tag=f352ba6a
Call-ID: MWVjZWExYzI3NDI0NjFlZjAzYTIzMTZmNDhhNDdlMGM.
CSeq: 2 REGISTER
Expires: 3600
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY,MESSAGE,SUBSCRIBE,INFO
Proxy-Authorization: Digest username="kaiwnAuth",realm="",nonce="c68b373754244ddebfe6170763732df6",uri="sip:192.168.1.112",response="4852279d2e03c34b326f2c015edd7722",algorithm=MD5,opaque="f9905829986f45fc960e4e11fe81129c"
User-Agent: X-Lite release 1103d stamp 53117
Content-Length: 0

<end>
Transaction [branch='z9hG4bK-d8754z-3938bc3f86545228-1---d8754z-';method='REGISTER';IsServer=true] created.
Transaction [branch='z9hG4bK-d8754z-3938bc3f86545228-1---d8754z-';method='REGISTER';IsServer=True] switched to 'Trying' state.
Response [flowReuse=true; transactionID='z9hG4bK-d8754z-3938bc3f86545228-1---d8754z-'; method='REGISTER'; cseq='2'; transport='UDP'; size='561'; statusCode='407'; reason='Proxy Authentication Required: Authentication failed.'; sent '192.168.1.112:5060' -> '192.168.1.112:37788'.
<begin>
SIP/2.0 407 Proxy Authentication Required: Authentication failed.
Via: SIP/2.0/UDP 127.0.0.1:37788;branch=z9hG4bK-d8754z-3938bc3f86545228-1---d8754z-;rport=37788;received=192.168.1.112
From: "kaiwn" <sip:kaiwn@192.168.1.112>;tag=f352ba6a
To: "kaiwn" <sip:kaiwn@192.168.1.112>;tag=f58d481f93aed3fd688a75ec
Call-ID: MWVjZWExYzI3NDI0NjFlZjAzYTIzMTZmNDhhNDdlMGM.
CSeq: 2 REGISTER
Allow: INVITE,ACK,CANCEL,BYE,MESSAGE
Proxy-Authenticate: digest realm="",nonce="96734a5506cd47db87eb254a058ddb13",opaque="f9905829986f45fc960e4e11fe81129c"
Content-Length: 0
*****************************************************************************************************************

I hope to debug this program with a client in the same computer, so that I can learn something from the great work.

Thanks
QuestionSystem.IndexOutOfRangeException: Pin
gokhanuslu17-Jun-09 4:18
gokhanuslu17-Jun-09 4:18 
Generalis there is client Pin
el3ashe211-Jun-09 2:54
el3ashe211-Jun-09 2:54 
GeneralRe: is there is client Pin
Ivar Lumi11-Jun-09 6:32
Ivar Lumi11-Jun-09 6:32 
GeneralRe: is there is client Pin
el3ashe213-Jun-09 22:42
el3ashe213-Jun-09 22:42 
GeneralRe: is there is client Pin
Ivar Lumi14-Jun-09 19:52
Ivar Lumi14-Jun-09 19:52 
GeneralRe: is there is client Pin
el3ashe215-Jun-09 1:54
el3ashe215-Jun-09 1:54 
GeneralRe: is there is client Pin
Ivar Lumi15-Jun-09 2:35
Ivar Lumi15-Jun-09 2:35 
GeneralDoes it work without setting domain Pin
lliaolx_guilin10-Jun-09 14:10
lliaolx_guilin10-Jun-09 14:10 
GeneralRe: Does it work without setting domain Pin
Ivar Lumi11-Jun-09 0:30
Ivar Lumi11-Jun-09 0:30 
GeneralRe: Does it work without setting domain Pin
lliaolx_guilin11-Jun-09 7:12
lliaolx_guilin11-Jun-09 7:12 
GeneralRe: Does it work without setting domain Pin
Ivar Lumi11-Jun-09 7:19
Ivar Lumi11-Jun-09 7:19 
GeneralRe: Does it work without setting domain Pin
lliaolx_guilin11-Jun-09 12:53
lliaolx_guilin11-Jun-09 12:53 
GeneralRe: Does it work without setting domain Pin
lliaolx_guilin11-Jun-09 7:57
lliaolx_guilin11-Jun-09 7:57 
GeneralRe: Does it work without setting domain Pin
Ivar Lumi12-Jun-09 3:55
Ivar Lumi12-Jun-09 3:55 
Generalx-Lite connect sip server error Pin
liwei198309163-Jun-09 16:25
liwei198309163-Jun-09 16:25 
GeneralRe: x-Lite connect sip server error Pin
Ivar Lumi3-Jun-09 19:30
Ivar Lumi3-Jun-09 19:30 
GeneralRe: x-Lite connect sip server error Pin
liwei198309163-Jun-09 21:01
liwei198309163-Jun-09 21:01 

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

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