How to develop custom VoIP PBX functionality?

Ozeki VoIP SIP SDK provides revolutionary technology for creating your own SIP PBX. To make your work easier it offers you default VoIP PBX behavior. This page explains the essential terms concerning simple VoIP PBX functionalities and how you can start to develop your own PBX with Ozeki SIP SDK.

What is a PBX?

A Private Branch Exchange (PBX) is a hardware or software solution for establishing communication lines between different types of communication end-points, regardless of using wired, mobile or VoIP technology (Figure 1). The PBX establishes the communication line between the end points through SIP accounts and SIP messages.

The core PBX functionalities are provided by Ozeki VoIP SIP SDK. This article introduces how you can implement a PBX software with default behavior. This simple PBX will be capable for handling registration requests from any extensions with any SIP accounts, and the calling process will be done in between two end points in the simplest way. It means that one party calls a number and the end point with that number will ring. When the callee answers the call, the phone line establishes and the communication can be done.

How to develop custom PBX using C#?

The following program code uses the background support of Ozeki VoIP SIP SDK, therefore you will need to download and install Ozeki SIP SDK on your computer before starting to use the program code. You will also need to have Visual Studio 2012 or compatible IDE and .NET Framework installed on your system, as the program code below is written in C# language.

When you want to write your own PBX software you will need to create a C# console application as a PBX does not necessarily need a graphical user interface. You will need to set the Ozeki VoIP SIP SDK as a reference for your project.

Since the custom pbx should be inherited from the PBXBase class, it can override the available methods of that, for example:

  • OnStart(): when the PBX's Start() method is being called, this method is being called as well. You can set here the transport type, local address, listening port etc.
  • OnRegisterReceiver(): when a register request cames from an extension, this method is being called.
  • OnUnregisterReceived(): when an extension sends request about unregistering, this method is being called.
  • OnCallRequestReceived(): when an extension tries to start a call, this method is being called first.

Custom PBX example in C#

using System;
using Ozeki.Network;
using Ozeki.VoIP;

namespace BasePBX_Simple
{
    internal class MainClass
    {
        private static void Main(string[] args)
        {
            var myPBX = new MyPBX(NetworkAddressHelper.GetLocalIP().ToString(), 20000, 20500);
            myPBX.Start();

            Console.ReadLine();
            myPBX.Stop();
        }
    }

    class MyPBX : PBXBase
    {
        string localAddress;

        public MyPBX(string localAddress, int minPortRange, int maxPortRange)
            : base(minPortRange, maxPortRange)
        {
            this.localAddress = localAddress;
            Console.WriteLine("PBX starting...");
            Console.WriteLine("Local address: " + localAddress);
        }

        protected override void OnStart()
        {
            SetListenPort(localAddress, 5060, TransportType.Udp);
            Console.WriteLine("Listened port: 5060(UDP)");

            Console.WriteLine("PBX started.");
            base.OnStart();
        }

        protected override RegisterResult OnRegisterReceived(ISIPExtension extension, SIPAddress from, int expires)
        {
            Console.WriteLine("Register received from: " + extension.ExtensionID);
            return base.OnRegisterReceived(extension, from, expires);
        }

        protected override void OnUnregisterReceived(ISIPExtension extension)
        {
            Console.WriteLine("Unregister received from: " + extension.ExtensionID);
            base.OnUnregisterReceived(extension);
        }

        protected override void OnCallRequestReceived(ISessionCall call)
        {
            Console.WriteLine("Call request received. Caller: " + call.DialInfo.CallerID + " callee: " + call.DialInfo.Dialed);
            base.OnCallRequestReceived(call);
        }
    }
}

Related Pages

More information