What you need for PBX development:

Step 1: Settings in Visual Studio

  • Create a new Visual Studio project (select the 'Visual C# Console Application' option)
  • To achieve and use the PBX components of Ozeki VoIP SIP SDK, add them to your references (the necessary SDK.dll file can be found where the SDK has been installed to)

Step 2: Coding

First you need to make a new class for your PBX. To use the SDK components and methods you need to add some using lines to the code:

   using Ozeki.VoIP.PBX;
   using Ozeki.VoIP.PBX.Extensions;
   using Ozeki.VoIP.PBX.PhoneCalls;
   using Ozeki.VoIP.SIP;
   using Ozeki.VoIP.Network;

Code 1: Add some new using lines

Now let's create a fully functional PBX that is able to register any SIP extensions and can establish phone lines in between them. When building a PBX, your PBX class needs to be derived from the PBXBase class provided by the SDK. Make a string type localAddress variable and then the constructor. It has three parameters: localAddress, minPortRange, maxPortRange. (localAddress is that address where the PBX listens the connecting clients. In addition to the IP address, your PC has several other ports since each application use another port. You need to set the port range, indicated by the first paramerter - minPortRange - and the maximum parameter - maxPortRange. This is the port's interval.) The localAddress will be equal to the parameter localAddress. After this you need to put two lines to the console : PBX Starting…, What is our local address (Code 2). Now, if a registered SIP endpoint calls an other SIP endpoint entering the SIP account information, the communication line will be established between them. (Actually, this is the default behaviour of a simple VoIP PBX.)

   namespace myPBX
   {
       class MyPBX : PBXBase
       {
           string localAddress;
           
           public MyPBX(string localAddress, int minPortRange, int maxPortRange) : base(minPortRange, maxPortRange){
               this.localAddress = localAssress;
               Console.WriteLine("PBX Starting...");
               Console.WriteLine("Local address: " + localAddress);
           } 
      }
   }

Code 2: The definition of the PBX class

You can extend your PBX functionality with authentication. Since by default, the OnRegisterReceived method allows any SIP account registrations to the PBX, just override the OnRegisterReceived method if you want to determine which extensions you will register and which you will not. So it's time to create an OnStart method. For this purpose, write the ’PBX started’ line to the console, then set up the listening port according to the following code extract (Code 3).
  • Parameters: localAddress, port number and the type of the transport (UDP)
  • Write a new line: Listened port number
  • Call the base.OnStart method
  • Create the OnRegisterReceived method using 3 parameters (extension, SIPaddress, expires)
  • Create the OnUnregisterReceived method using 1 parameter (extension)

   protected override void OnStart()
   { 
       Console.WriteLine("PBX started.");
       SetListenPort(localAddress,5060,TransportType.Udp);
       
       Console.WriteLine("Listened port: 5060(UDP)");
       base.OnStart();
   } 
   
   protected override RegisterResult OnRegisterReceived(ISIPExtension extension, SIPAddress from, int expires)
   {
       Console.WriteLine("Register received from: " + extension.Account.Username);
       return base.OnRegisterReceived(extension, from, expires);
   }
   
   protected override void OnUnregisterReceived(ISIPExtension extension)
   {
       Console.WriteLine("Unregister received from: " + extension.Account.UserName);
       base.OnUnregisterReceived(extension);
   }

Code 3: The creation of the OnStart method

For making the main method for your PBX, you need to add one more new using line to the code:

   using Ozeki.Network;

Code 4: Add one more new using line

Code 5 shows how to code the main method:

   namespace myPBX
   { 
       class Program
       { 
           static void Main(string[] args)
           {
               var myPBX = new MyPBX(NetworkAddressHelper.GetLocalIP().ToString(), 20000, 20500);
               
               myPBX.Start();
               
               Console.ReadLine();
               myPBX.Stop();
           } 
       } 
   } 

Code 5: The main method

Having done these steps, run the application. If it works, your PBX system is ready to accept SIP account registrations, moreover it can be perfectly used to make/receive audio phone calls using the registered SIP extensions.

Step 3: Making a test call

First of all, it is recommended to test SIP registration with an IP telephone. (If you don't have any IP phones, the best option is using Ozeki's demo softphone application that has been installed automatically with the SDK.) After you have provided the required SIP account details, the register line appears in your console application in case of successful registration (Figure 1):

voip_pbx_test_successful_SIP_account_registration.jpg
Figure 1: The SIP account registration was successful

After testing the SIP registration, it is also recommended to make a test call. For this purpose, you need to register two SIP accounts: A-Extension and B-Extension. (In addition to Ozeki's demo softphone application, you can download X-Lite softphone free of charge as a second IP telephone.) After the SIP registration, pick A-Extension and dial the phone number of B-Extension. B-Extension will be ringing. After the called party has accepted the call, the phone line is established between them.

Summary

The most simplest way for developing your own SIP PBX is using prewritten PBX components. Ozeki VoIP SIP SDK is a really effective tool if you want to focus on developing your application instead of worrying about necessary network protocols and technical details. As simple as that!

Additional information


How to build advanced VoIP PBX features

Due to the VoIP technology, it's easy to extend your PBX with some additional functionalities. Get more information on how to build some advanced VoIP features to your PBX:

Download required software:

Further VoIP example projects:

Good luck!

Last edited Mar 10, 2014 at 12:21 PM by simonrobert, version 11