How to develop a VoIP softphone in C# by using Ozeki VoIP SIP SDK

100 %
0 %
Information about How to develop a VoIP softphone in C# by using Ozeki VoIP SIP SDK
Product-Training-Manuals

Published on March 12, 2014

Author: willmoore

Source: authorstream.com

How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK: How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation demonstrates the first steps concerning to how to develop a fully-functional softphone in C# in the most simplest way - by using the previously written components of Ozeki VoIP SIP SDK. development tutorial The great softphone Part 1  Part 1: SIP registration Part 2: Making and receiving calls Part 3: Controlling the calls 1/15 What you need: What you need Windows PC .NET compatible development kit (e.g. MS Visual Studio) installed on your PC .NET Framework installed on your PC Ozeki VoIP SIP SDK installed on your PC In order to build a VoIP softphone application in C# you will need the followings: 2/15 Download free example source code for this project from http://voip-sip-sdk.com/p_539-sip-registration-voip.html ! Create a new Microsoft Visual Studio project and add VoIP components to your references: Creat e a new Microsoft Visual Studio project and add VoIP components to your references Open Visual Studio  and create a new projec t by clicking on  File  then  New project As this softphone will be a simple console application , in the next window you need to select the  Visual C# Console Application  option After you have specified a name for your new project, click on the  OK  button To achieve and use the  VoIP components of the SDK , add them to your references For this, you need to right-click on  References  than select the  Add references  option. After this,  browse the SDK.dll  file that can be found where the SDK has been installed to. Select the .dll and click on the OK  button Having done these steps, y ou can find a new line at the end of the References folder: ‘ VoIPSDK ’ . This line indicates that now y ou can use the tools provided by the SDK. 3/15 Write the code Classes: For separat ing the softphone from the user interface , two classes are used : Softphone.cs: The implementation of the softphone goes here (including its events, methods, functions, variables ) T his class is used to introduce how to declare, define and initialize a softphone, how to handle some of the Ozeki VoIP SIP SDK's events and how to use some features . So the aim is creating a ‘t elephone software ’ , which has the same functionalities (or much more), as an ordinary phone ’s . Program.cs : The class with the Main() method ( this class controls the console window, interacts with the user by using a softphone object ) You will use the Program.cs class to create a new softphone, so you can use the functions and listen to the events placed here. Write the code Classes 4/15 Write the code Source code analysis: In the ‘ using section ’ you need to add some extra lines, as well as : Without these lines you would have to use the namespace information as a label for all tools of the SDK. Write the code Source code analysis using  Ozeki.Network.Nat;   using  Ozeki.VoIP;   using  Ozeki.VoIP.SDK;   5/15 Write the code Softphone.cs: In a constructor, you also need to initialize this softphone with default parameters : You need to set the port range, indicated by the first two parameters as the minimum port's and the maximum port's number . T his is the port's interval. The third parameter is the listening port. If you have any firewall rule that restricts the usable ports, you can set the usable port range here, which will be used during the calls. These are sample ports only in the example, but a softphone with these parameters can be used in the most of the cases. (If y ou are handling conference calls or handling a lot of lines simultaneously, y ou will need a wide port range. ) Write the code Softphone.cs ISoftPhone softphone;    // softphone object   IPhoneLine phoneLine;    // phoneline object    softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000, 5060);     C reate a softphone and a phone line object from the ISoftPhone and the IPhoneLine interfaces: 6/15 Write the code Registration to the PBX: In order to create the SIP accoun t, set the followings: RegistrationRequired: Is the registration required or not? This field needs to be set to ‘ true ’ , if you would like to receive incoming calls DisplayName:   A name to be displayed at the called client . UserName:   I f an other client dials this name (number), the SIP account will be ge tting called AuthenticationId:   A n identifier to the PBX, like a login name RegisterPassword:   T he password that register s to the PBX. It w orks in pair with the authentication ID DomainHost:   For example a domain name, an IP address DomainPort:   P ort number The last two values defin e the PBX address where t he softphone will be register ed. You will get the values of these parameters from the user, in the Program.cs file. Write the code Registration to the PBX var account = SIPAccount(registrationRequired, displayName, userName, <br> authenticationId, registerPassword, domainHost, domainPort);   7/15 Write the code NAT (Network Address Translation) Traversal: If you want to communicate through firewall , you need to set the right NAT Traversal method : In th is example, it has been set to ‘ None ’ . This is enough for communicat ion on local network. An other option for the NAT Traversal method is setting it to ‘ STUN ’ . This way, you can define the Stun server with a NatRemoteServer object by giving the server IP, the username and password to use as parameters:   You can set automated detect ion on that IP address you would like to use. If you set the configuration to ‘ None ’ , but you also set a NatRemoteServer object with the public IP, you will use the local address on the local network and the public on others: Write the code NAT (Network Address Translation) Traversal var natConfiguration = NatConfiguration(NatTraversalMethod.None);     natConfiguration.StunServer =  new  NatRemoteServer(serverIP, username, password);  natConfiguration.AutoDetect =  true ;      8/15 Write the code PhoneLine: In order t o communicate (and to register to the PBX) you need to create a phone line by using the previously created SIP account and the NAT Traversal setup : When the application is running, the state of the phone line can change. To follow these changes, you need to listen to this change event:   When the phone line has been created, you have to call the RegisterPhoneLine() method to register the phone line to the softphone. If the registration is set to required, this method will also send the SIP REGISTER command. You only need to use the following line: Write the code PhoneLine phoneLine = softphone.CreatePhoneLine(account, natConfiguration)      phoneLine.PhoneLineStateChanged += phoneLine_PhoneLineStateChanged; softphone.RegisterPhoneLine(phoneLine);       9/15 Write the code Events: 10/15 The phone line event can be in several states, for example: RegistrationFailed:  occurs, when registration is needed, but it failed . The phone is unable to communicate through the PBX NoRegNeeded:  there is no communication with the server, until the first (made) call. If you ha ve set any invalid information during the SIP account creation, you can no t even make call s . Since y our softphone is not registered to the server, you can not receive any calls, even with valid SIP account RegistrationSucceeded:  occurs, when registration is needed, and succeeded. The phone is able to receive and make calls RegistrationTimedOut:  some PBX s define for how long a client can be registered to it. If that time is up, the state of the phone line changes to this Write the code Events Write the code Program.cs: This class will introduce the usage of a softphone object, it handles the console events, interacts with the user and uses the opportunities provided by the Softphone class. In this example, the softphone can only register to a PBX by the values given by the user. First of all, you need to create a softphone object. You can handle everything with separated methods. These methods are communicating with each other, and making the source code more understandable and reusable. Write the code Program.cs static  Softphone mySoftphone;        11/15 Write the code Initialization: In order to initialize your softphone , you need to call an initializer method with the following lines:   Call this method in the Main() method. Now, there is a new softphone available to use, and it i s already following the states of the phone. You will see how to handle the states below, after you have done with the greeting and the registration process. Write the code Initialization mySoftphone =  new  Softphone();   mySoftphone.PhoneLineStateChanged += mySoftphone_PhoneLineStateChanged;          Showin g a greeting message I n a few lines you can introduce  the application to the user. It i s preferred to say a few sentences about the features available. After y our softphone has been initialized, call this method to introduce the application in the Main() method. 12/15 Write the code Creating the SIP account by the user's input and registering to a PBX: As you could see at the Softphone class, you need a  configured SIP account in order to use the softphone for communication. The user needs to enter valid values to create a SIP account and to  register to a PBX . This procedure can be done using such simple commands as : Write the code Creating the SIP account by the user's input and registering to a PBX Console.WriteLine();   Console.ReadLine();          13/15 Write the code Handling of the phone line states: You are subscribed to get notified if the state of the phone line has been changed. At the mySoftphone_PhoneLineStateChanged  method you can set what happens in case of each state. If the  registration is failed , the SIP account details should be provided again . States for this case: o r The "RegistrationFailed" state occurs, when the registration is simply unsuccessful, for example, if the user set up invalid SIP account during the regist ration . The "RegistrationTimedOut" state occurs, if the registration request takes too long. If the  registration has succeeded  or there is  no need for registration , you can notify the user about that . N ote , if there is no need for registration, but you could not reach the PBX (or you could, but with invalid SIP account), you will not notice that until you make y our first call. The states to use: Write the code Handling of the phone line states PhoneLineState.RegistrationTimedOut          PhoneLineState.RegistrationFailed          PhoneLineState.RegistrationSucceeded   PhoneLineState.NoRegNeeded 14/15 Check the 2. part of the ‘How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK’ tutorial series and get to know how to make and receive calls using your softphone!: Check the 2. part of the ‘How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK’ tutorial series and get to know how to make and receive calls using your softphone! After studying this tutorial , you need be familiar with add ing VoIP components to your references and creat ing a Softphone class that provides a softphone object to the user usign the input setups. Now you have a console window which interact s with the user and handl es y our softphone with the provided opportunities. development tutorial The great softphone Part 1 Thank you for your attention! For more information please visit www.voip-sip-sdk.com or send an e-mail to info@voip-sip-sdk.com 15/ 15

Add a comment

Related presentations

Related pages

Ozeki C# SIP Stack - Ozeki VoIP SIP SDK Home Page

... the home page of ozeki voip sip sdk. this is the best ... to develop a softphone in C#. ... can develop a simple SIP softphone for audio VoIP SIP ...
Read more

How to build a C# open source VoIP softphone with WPF GUI ...

... source voip softphone with wpf gui using ozeki sip sdk. ... a c# open source voip softphone with wpf gui using ... develop C# WPF softphone?
Read more

#3 How to develop a SIP PBX in C# by using Ozeki VoIP SIP ...

... to how to build a SIP PBX by using Ozeki VoIP SIP SDK. ... develop a SIP PBX in C# by ... a softphone by using Ozeki VoIP SIP SDK ...
Read more

#3 How to develop a softphone by using Ozeki VoIP SIP SDK ...

... a softphone by using Ozeki VoIP SIP SDK. ... develop a SIP PBX in C# by using Ozeki VoIP ... VoIP Account and VoIP/SIP Softphone ...
Read more

CodePlex - How to build a VoIP softphone in C# - Home

... develop a fully-functional VoIP softphone ... to develop a fully-functional softphone in C# in ... using dedicated hardware. Ozeki VoIP SIP SDK ...
Read more

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

How to Build a .NET Softphone in C# with SIP, ... to give up using my own written ... presented on Ozeki VoIP SIP SDK ...
Read more

Creating a C# Softphone - C# Corner - Developers and IT ...

Creating a C# Softphone. ... The new version of the Ozeki VoIP SIP SDK I ... I need to say thanks to the great developer and support teams of Ozeki ...
Read more