Click here to Skip to main content
12,824,787 members (42,372 online)
Click here to Skip to main content
Add your own
alternative version

Stats

799.1K views
23.9K downloads
159 bookmarked
Posted 20 Mar 2007

SIP Stack with SIP Proxy - (VOIP)

, 11 Jun 2007 CPOL
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

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)

Share

About the Author

Ivar Lumi
Estonia Estonia
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionGetting 403 Forbidden error Pin
Shishir Shetty13-Feb-14 6:12
memberShishir Shetty13-Feb-14 6:12 
GeneralMy vote of 3 Pin
Mic6-Aug-13 15:26
memberMic6-Aug-13 15:26 
Questionstudy sip Pin
ape1236-Apr-13 1:02
memberape1236-Apr-13 1:02 
Questioncalling bug Pin
shadi2422-Nov-12 0:22
membershadi2422-Nov-12 0:22 
Bugzero?o? Pin
Member 883330021-Jun-12 17:43
memberMember 883330021-Jun-12 17:43 
Bugbug Pin
Member 883330017-Jun-12 1:46
memberMember 883330017-Jun-12 1:46 
GeneralRe: bug Pin
Ivar Lumi17-Jun-12 23:05
memberIvar Lumi17-Jun-12 23:05 
QuestionHow to Register IP Phone ??? Pin
kelibox23-Aug-11 2:04
memberkelibox23-Aug-11 2:04 
IPPhone IP is 192.168.1.2; Sip Proxy IP is 192.168.1.253
When IPPhone Register , the SIP fails the process and shows the error.
What can I do to resolve it ?
////// error log//////////
System.FormatException: 輸入字串格式不正確。(translation: input string wrong)
於 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
於 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
於 System.Convert.ToInt32(String value)
於 LumiSoft.Net.AUTH.Auth_HttpDigest.Parse(String digestResponse) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\AUTH\Auth_HttpDigest.cs: 行(row) 126
於 LumiSoft.Net.AUTH.Auth_HttpDigest..ctor(String digestResponse, String requestMethod) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\AUTH\Auth_HttpDigest.cs: 行 35
於 LumiSoft.Net.SIP.SIP_Utils.GetCredentials(SIP_Request request, String realm) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\SIP_Utils.cs: 行 145
於 LumiSoft.Net.SIP.Proxy.SIP_Proxy.AuthenticateRequest(SIP_RequestReceivedEventArgs e, String& userName) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Proxy\SIP_Proxy.cs: 行 823
於 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: 行 351
於 LumiSoft.Net.SIP.Proxy.SIP_Proxy.OnRequestReceived(SIP_RequestReceivedEventArgs e) 於 D:\Csharp Book\LumiSoft.Net\Net\Net\SIP\Proxy\SIP_Proxy.cs: 行 174
///////reg log////////
Transaction [branch='z9hG4bK4e8808b81af58f0f0f98f9fae0fa8ac6';method='REGISTER';IsServer=true] timer I(Non-INVITE request retransmission wait) triggered.
Transaction [branch='z9hG4bK4e8808b81af58f0f0f98f9fae0fa8ac6';method='REGISTER';IsServer=True] switched to 'Terminated' state.

Request [method='REGISTER'; cseq='781'; transport='UDP'; size='401'; received '192.168.1.2:5060' -> '192.168.1.253:5060'.

REGISTER sip:192.168.1.253 SIP/2.0
Call-ID: 4099112003-3E8B-0007
Contact:
CSeq: 781 REGISTER
Expires: 3600
From: "101" ;tag=50-831083433
Max-Forwards: 70
To: "101"
User-Agent: AmRoad
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bKed119c3b6e431f736168068fd9086387;received=192.168.1.2
Content-Length: 0


Transaction [branch='z9hG4bKed119c3b6e431f736168068fd9086387';method='REGISTER';IsServer=true] created.
Transaction [branch='z9hG4bKed119c3b6e431f736168068fd9086387';method='REGISTER';IsServer=True] switched to 'Trying' state.
Response [flowReuse=true; transactionID='z9hG4bKed119c3b6e431f736168068fd9086387'; method='REGISTER'; cseq='781'; transport='UDP'; size='505'; statusCode='407'; reason='Proxy Authentication Required'; sent '192.168.1.253:5060' -> '192.168.1.2:5060'.


SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bKed119c3b6e431f736168068fd9086387;received=192.168.1.2
From: "101" ;tag=50-831083433
To: "101" ;tag=91b64c1f81bef5e95e30cea3
Call-ID: 4099112003-3E8B-0007
CSeq: 781 REGISTER
Allow: INVITE,ACK,CANCEL,BYE,MESSAGE
Proxy-Authenticate: digest realm="",nonce="61bc850c786241f19f57580448a9480b",opaque="1d795f4460ec4cfd9892f4ecd50d91c7"
Content-Length: 0


Transaction [branch='z9hG4bKed119c3b6e431f736168068fd9086387';method='REGISTER';IsServer=True] switched to 'Completed' state.
Transaction [branch='z9hG4bKed119c3b6e431f736168068fd9086387';method='REGISTER';IsServer=true] timer J(Non-INVITE request retransmission wait) started, will trigger after 32000.
Request [method='REGISTER'; cseq='782'; transport='UDP'; size='626'; received '192.168.1.2:5060' -> '192.168.1.253:5060'.

REGISTER sip:192.168.1.253 SIP/2.0
Call-ID: 4099112003-3E8B-0007
Contact:
CSeq: 782 REGISTER
Expires: 3600
From: "101" ;tag=50-831083433
Max-Forwards: 70
Proxy-Authorization: Digest username="101@test.com",realm="",nonce="61bc850c786241f19f57580448a9480b",uri="sip:192.168.1.253",response="5dce688c47b46a36dddfe8b8c162fbf8",opaque="1d795f4460ec4cfd9892f4ecd50d91c7",nc=0000030e
To: "101"
User-Agent: AmRoad
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bK32d8da85d26639c06759a5a1082c56fa;received=192.168.1.2
Content-Length: 0


Response [transactionID=''; method='REGISTER'; cseq='782'; transport='UDP'; size='409'; statusCode='500'; reason='Server Internal Error: 輸入字串格式不正確。'; sent '' -> '192.168.1.2:5060'.

SIP/2.0 500 Server Internal Error: 頛詨摮葡?澆?銝迤蝣箝€?
Via: SIP/2.0/UDP 192.168.1.2:5060;rport=5060;branch=z9hG4bK32d8da85d26639c06759a5a1082c56fa;received=192.168.1.2
From: "101" ;tag=50-831083433
To: "101" ;tag=0f7c40ad88cb505d4fb3ece3
Call-ID: 4099112003-3E8B-0007
CSeq: 782 REGISTER
Allow: INVITE,ACK,CANCEL,BYE,MESSAGE
Content-Length: 0

Transaction [branch='z9hG4bKed119c3b6e431f736168068fd9086387';method='REGISTER';IsServer=true] timer I(Non-INVITE request retransmission wait) triggered.
Transaction [branch='z9hG4bKed119c3b6e431f736168068fd9086387';method='REGISTER';IsServer=True] switched to 'Terminated' state.
AnswerRe: How to Register IP Phone ??? Pin
Ivar Lumi23-Aug-11 2:07
memberIvar Lumi23-Aug-11 2:07 
GeneralRe: How to Register IP Phone ??? Pin
kelibox24-Aug-11 4:56
memberkelibox24-Aug-11 4:56 
GeneralRe: How to Register IP Phone ??? Pin
Ivar Lumi24-Aug-11 5:15
memberIvar Lumi24-Aug-11 5:15 
GeneralRe: How to Register IP Phone ??? Pin
kelibox25-Aug-11 14:26
memberkelibox25-Aug-11 14:26 
QuestionHow to set enviroenment Pin
bliznak220-Jul-11 4:31
memberbliznak220-Jul-11 4:31 
AnswerRe: How to set enviroenment Pin
Ivar Lumi20-Jul-11 20:11
memberIvar Lumi20-Jul-11 20:11 
Generalvoip sip client with video Pin
waelsys200724-May-11 2:33
memberwaelsys200724-May-11 2:33 
GeneralRe: voip sip client with video Pin
Ivar Lumi24-May-11 3:41
memberIvar Lumi24-May-11 3:41 
GeneralA question about RTCP Pin
ywchen8-Apr-11 16:17
memberywchen8-Apr-11 16:17 
GeneralRe: A question about RTCP Pin
Ivar Lumi8-Apr-11 21:10
memberIvar Lumi8-Apr-11 21:10 
GeneralRe: A question about RTCP Pin
ywchen12-Apr-11 13:58
memberywchen12-Apr-11 13:58 
GeneralRe: A question about RTCP Pin
Ivar Lumi12-Apr-11 20:01
memberIvar Lumi12-Apr-11 20:01 
GeneralSIP_Authenticate AuthContext cannot get the password of the client application Pin
Sing52012-Mar-11 19:07
memberSing52012-Mar-11 19:07 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application Pin
Ivar Lumi2-Mar-11 20:12
memberIvar Lumi2-Mar-11 20:12 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application Pin
Sing52012-Mar-11 20:15
memberSing52012-Mar-11 20:15 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application Pin
Ivar Lumi2-Mar-11 20:17
memberIvar Lumi2-Mar-11 20:17 
GeneralRe: SIP_Authenticate AuthContext cannot get the password of the client application Pin
Sing52012-Mar-11 20:24
memberSing52012-Mar-11 20:24 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 11 Jun 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid