CheckConnection Method

Summary

Determines whether the server exists without making a connection.

Syntax
C#
VB
C++
[DispIdAttribute(1)] 
void CheckConnection(  
   string URL, 
   int Flags, 
   int Timeout 
) 
  
<DispIdAttribute(1)> 
Sub CheckConnection( _ 
   ByVal URL As String, _ 
   ByVal Flags As Integer, _ 
   ByVal Timeout As Integer _ 
)  
[DispIdAttribute(1)] 
void CheckConnection(  
   String^ URL, 
   int Flags, 
   int Timeout 
)              

Parameters

URL
A System.String that contains the server address to be checked.

Flags
Value that indicates whether the method should negotiate the user name and password. Possible values are:

Value Meaning
0 Do not negotiate the user name and password.
NetSrc_CC_ForceConnection Negotiate the user name and password.

Timeout
Value that represents the amount of time, in milliseconds, to wait for the connection check before failing.

Return Value

S_OK if the function was successful.

<>S_OK if an error occurred. Refer to the Error Codes or the HRESULT error codes in the DirectShow documentation.

Example
C#
VB
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
public bool _result = false; 
public CaptureAndPlayCtrlForm _serverAndClient = new CaptureAndPlayCtrlForm(); 
 
CaptureCtrl _captureCtrl; 
PlayCtrl _playCtrl; 
 
const string _networkUrl = @"ltsf://127.0.0.1:27015"; // network stream url 
const string _testMessage = "LEAD NETWORK"; 
 
public void NetworkSourceExample() 
{ 
   // reference the capture control 
   _captureCtrl = _serverAndClient.CaptureCtrl; 
 
   // reference the play control 
   _playCtrl = _serverAndClient.PlayCtrl; 
 
   try 
   { 
      // try to find a video camera 
      if (_captureCtrl.VideoDevices["Logitech"] == null) 
         throw new Exception("No Logitech video device available"); 
 
      _captureCtrl.VideoDevices["Logitech"].Selected = true; 
 
      // select a video compressor 
      _captureCtrl.VideoCompressors.Mpeg4.Selected = true; 
 
      // set the target output file 
      _captureCtrl.TargetFormat = TargetFormatType.NET; 
      _captureCtrl.TargetFile = _networkUrl; 
 
      if (_captureCtrl.IsModeAvailable(CaptureMode.Video)) 
      { 
         // just 10 seconds of capture time 
         _captureCtrl.TimeLimit = 10; 
         _captureCtrl.UseTimeLimit = true; 
 
         _captureCtrl.FrameRate = 30; 
         _captureCtrl.UseFrameRate = true; 
 
         _captureCtrl.Preview = true; 
 
         // subscribe to the started and progress events for this example 
         // we will connect a client after the capture starts 
         _captureCtrl.Started += new EventHandler(CaptureCtrl_Started); 
 
         // ready the capture graph in order to get the LNMetMux instance 
         _captureCtrl.ReadyCapture(CaptureMode.Video); 
 
         // start capture 
         _captureCtrl.StartCapture(CaptureMode.Video); 
 
         // we'll loop on the state and pump messages for this example. 
         // but you should not need to if running from a Windows Forms application. 
         while (_captureCtrl.State == CaptureState.Running 
               || _playCtrl.State == PlayState.Running) 
         { 
            Application.DoEvents(); 
         } 
      } 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
} 
 
void CaptureCtrl_Started(object sender, EventArgs e) 
{ 
   StartClient(); 
} 
 
private void StartClient() 
{ 
   try 
   { 
      LMNetSrc netSrc = new LMNetSrc(); 
      netSrc.CheckConnection(_networkUrl, 0, 5000); 
      _result = true; 
      Marshal.ReleaseComObject(netSrc); 
   } 
   catch (COMException) 
   { 
      // could not connect 
      _result = false; 
      return; 
   } 
 
   // connects the client player 
   _playCtrl.SourceFile = _networkUrl; 
} 
Imports Leadtools 
Imports Leadtools.Multimedia 
Imports LeadtoolsMultimediaExamples.Fixtures 
 
Public _result As Boolean = False 
Public _serverAndClient As CaptureAndPlayCtrlForm = New CaptureAndPlayCtrlForm() 
 
Private _msgSent As Boolean = False 
Private _captureCtrl As CaptureCtrl 
Private _playCtrl As PlayCtrl 
 
Private Const _networkUrl As String = "ltsf://127.0.0.1:27015" ' network stream url 
Private Const _testMessage As String = "LEAD NETWORK" 
 
Public Sub NetworkSourceExample() 
   ' reference the capture control 
   _captureCtrl = _serverAndClient.CaptureCtrl 
 
   ' reference the play control 
   _playCtrl = _serverAndClient.PlayCtrl 
 
   Try 
      ' try to find a video camera 
      If _captureCtrl.VideoDevices("Logitech") Is Nothing Then 
         Throw New Exception("No Logitech video device available") 
      End If 
 
      _captureCtrl.VideoDevices("Logitech").Selected = True 
 
      ' select a video compressor 
      _captureCtrl.VideoCompressors.Mpeg4.Selected = True 
 
      ' set the target output file 
      _captureCtrl.TargetFormat = TargetFormatType.NET 
      _captureCtrl.TargetFile = _networkUrl 
 
      If _captureCtrl.IsModeAvailable(CaptureMode.Video) Then 
         ' just 10 seconds of capture time 
         _captureCtrl.TimeLimit = 10 
         _captureCtrl.UseTimeLimit = True 
 
         _captureCtrl.FrameRate = 30 
         _captureCtrl.UseFrameRate = True 
 
         _captureCtrl.Preview = True 
 
         ' subscribe to the started and progress events for this example 
         ' we will connect a client after the capture starts 
         AddHandler _captureCtrl.Started, AddressOf CaptureCtrl_Started 
 
         ' ready the capture graph in order to get the LNMetMux instance 
         _captureCtrl.ReadyCapture(CaptureMode.Video) 
 
         ' start capture 
         _captureCtrl.StartCapture(CaptureMode.Video) 
 
         ' we'll loop on the state and pump messages for this example. 
         ' but you should not need to if running from a Windows Forms application. 
         Do While _captureCtrl.State = CaptureState.Running OrElse _playCtrl.State = PlayState.Running 
            Application.DoEvents() 
         Loop 
      End If 
   Catch e1 As Exception 
      _result = False 
   End Try 
End Sub 
 
Private Sub CaptureCtrl_Started(ByVal sender As Object, ByVal e As EventArgs) 
   StartClient() 
End Sub 
 
Private Sub StartClient() 
   Try 
      Dim netSrc As LMNetSrc = New LMNetSrc() 
      netSrc.CheckConnection(_networkUrl, 0, 5000) 
      _result = True 
      Marshal.ReleaseComObject(netSrc) 
   Catch cex As COMException 
      ' could not connect 
      _result = False 
      Return 
   End Try 
 
   ' connects the client player 
   _playCtrl.SourceFile = _networkUrl 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2019.9.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.