Share via


Create an Outgoing Application Session

The following code example demonstrates how to create an outgoing application session (RTCST_APPLICATION). The operations in the Initialize RTC code example must be performed before using this example.

Note  This example does not contain error checking or releases appropriate for real code.

C++ Code Example

IRTCSession2    *pIRTCSession2          = NULL;
IRTCParticipant *pIRTCParty             = NULL;
BSTR            bstrDestURI             = SysAllocString(L"someone@microsoft.com");
BSTR            bstrContentType         = SysAllocString(L"application/sdp");
BSTR            bstrSessionDescription  = // Specify the Session Description ;

// Create an outgoing Application session.
// Note: The ContentType and SessionDescription are 
// defined by the application. The example shows
// ContentType as "application/sdp", but this is only 
// one possibility; the ContentType could be anything.
hr = pIRTCClient2->CreateSessionWithDescription(bstrContentType,
                                                bstrSessionDescription,
                                                NULL,   // Let RTC choose the best profile
                                                0,        
                                                &pIRTCSession2);

// If (hr != S_OK), process the error here. 

// Add the participant.
hr = pIRTCSession2->AddParticipant(bstrDestURI,
                                   NULL,
                                   &pIRTCParty);

// If (hr != S_OK), process the error here. 

// Wait for the RTCE_SESSION_STATE_CHANGE event of 
// type RTCSS_CONNECTED before performing operations 
// on the session. 

Visual Basic Code Example

Dim objSession2 As IRTCSession2
Dim objParticipant As IRTCParticipant
Dim strDestURI As String      '(for example, someone@microsoft.com)
Dim strDestName As String     '(for example, Jeff Smith)
Dim strContentType As String  '(for example, application/sdp)
Dim strSessionDescription As String   '(Specify the Session Description)

' Create an outgoing Application session.
Set objSession2 = objRTCClient2.CreateSessionWithDescription(strContentType, _
                                                             strSessionDescription, _
                                                             Nothing, _
                                                             0)              
' If (Err.Number), process the error here. 

' Add a participant to the session.
Set objParticipant = objSession2.AddParticipant(strDestURI, _
                                                strDestName)

' Wait for the RTCE_SESSION_STATE_CHANGE event of 
' type RTCSS_CONNECTED before performing operations 
' on the session.