-
Notifications
You must be signed in to change notification settings - Fork 442
Developers
Aaron Clauson edited this page Jul 18, 2018
·
2 revisions
1. Create a new C# Console application in Visual Studio,
2. Use the Nuget Package Manager and install the SIPSorcery package,
3. Cut and paste in the code below to send a test INVITE request to your SIP phone or softphone.
// ============================================================================
// Description:
// This program provides a minimal example of how to use the SIP Sorcery SIP stack
// to initiate a call to an external user agent. The example sets up the SIP transport
// and then fires off an empty INVITE request to the destination SIP user agent.
// No media is negotiated and no incoming SIP requests are handled.
//
// Author(s):
// Aaron Clauson
//
// License:
// This software is licensed under the BSD License http://www.opensource.org/licenses/bsd-license.php
// ============================================================================
using System;
using System.Net;
using SIPSorcery.SIP;
using SIPSorcery.SIP.App;
using SIPSorcery.Sys;
namespace SIPSorcery.Test
{
class Program
{
// The SIP stack internals will bubble log messages up. use this delegate to spit them out to the console.
private static SIPMonitorLogDelegate _logDelegate = (evt) => {
if (evt is SIPMonitorConsoleEvent) {
Console.WriteLine(((SIPMonitorConsoleEvent)evt).ToConsoleString("*"));
}
};
static void Main(string[] args)
{
try
{
Console.WriteLine("SIPSorcery Example:");
// Set up the SIP transport infrastructure.
SIPTransport sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine());
SIPUDPChannel udpChannel = new SIPUDPChannel(new IPEndPoint(IPAddress.Any, 5060));
sipTransport.AddSIPChannel(udpChannel);
// Create a SIP user agent client that can be used to initiate calls to external SIP devices and place a call.
SIPClientUserAgent uac = new SIPClientUserAgent(sipTransport, null, null, null, _logDelegate);
SIPCallDescriptor callDescriptor = new SIPCallDescriptor("anonymous", null, "sip:anon@10.1.1.15:6060", "<sip:anon@10.1.1.2>", null, null, null, null, SIPCallDirection.Out, "application/sdp", null, null);
uac.Call(callDescriptor);
Console.WriteLine("Hit any key to cancel call...");
Console.Read();
sipTransport.Shutdown();
}
catch(Exception excp)
{
Console.WriteLine("Exception Main. " + excp);
}
finally
{
Console.Write("press any key to exit...");
Console.ReadLine();
}
}
}
}