Click here to Skip to main content
13,052,696 members (62,101 online)
Click here to Skip to main content


41 bookmarked
Posted 18 Mar 2011

How to Build a .NET Softphone in C# with SIP, SDP, RTP and RTCP

, 18 Mar 2011
Essay and tutorial about how to easily build a softphone application

Editorial Note

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VoIP;
using VoIP.SDK;

namespace FunnyPhone
    class Program
        static Dictionary<string,IPhoneCall> Calls;
        static PongCallListener FunnyCallListener;

        static void Main(string[] args)
            ISoftPhone SoftPhone = new SoftPhone("", 5000, 8000, 5060);
            //ISoftPhone SoftPhone = new VoIP.SDK.Mock.ArbSoftPhone();
            SoftPhone.IncommingCall += (SoftPhone_IncommingCall);
            IPhoneLine PhoneLine = null;
            FunnyCallListener = new PongCallListener();

            Calls = new Dictionary<string, IPhoneCall>();

            Console.WriteLine("Be funny!");

            Console.Write("Display name: "); string displayName = Console.ReadLine();
            Console.Write("Username: "); string username = Console.ReadLine();
            Console.Write("Register name: "); string registerName = Console.ReadLine();
            Console.Write("Register password: "); string registerPassword = Console.ReadLine();
            Console.Write("Domain server: "); string domainServer = Console.ReadLine();

            string[] domains = domainServer.Split(':');
            int port = 5060;
            if (domains.Length == 2)
                port = Int32.Parse(domains[1]);
            SIPAccount account = new SIPAccount(true, displayName, username, registerName, registerPassword, domains[0], port);
            PhoneLine = SoftPhone.CreateAndRegisterPhoneLine(account);

            while (true)
                string statement = Console.ReadLine().Trim();
                if (statement.StartsWith("exit"))

                if (!Calls.ContainsKey(statement))
                    if (PhoneLine.RegisteredInfo == PhoneLineInformation.RegistrationSucceded)
                        IPhoneCall Call = SoftPhone.CreateCallObject(PhoneLine, statement, FunnyCallListener);
                        Calls.Add(statement, Call);
                        Call.CallStateChanged += (Call_CallStateChanged);
            foreach (IPhoneCall call in Calls.Values)

        static void SoftPhone_IncommingCall(object sender, VoIPEventArgs<IPhoneCall> e)
            e.Item.CallStateChanged += (Call_CallStateChanged);
            Calls.Add(e.Item.DialInfo, e.Item);

        static void Call_CallStateChanged(object sender, VoIPEventArgs<CallState> e)
            if (e.Item > CallState.InCall)
                IPhoneCall call = sender as IPhoneCall;
                if (call == null)


                call.CallStateChanged -= (Call_CallStateChanged);


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


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


About the Author

No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 18 Mar 2011
Article Copyright 2011 by Esteban Murandi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid