Determines whether the server exists without making a connection.
Syntax
Visual Basic (Usage) | Copy Code |
---|
Dim instance As ILMNetSrc
Dim URL As String
Dim Flags As Integer
Dim Timeout As Integer
instance.CheckConnection(URL, Flags, 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
Visual Basic | Copy Code |
---|
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 |
C# | Copy Code |
---|
public bool _result = false;
public CaptureAndPlayCtrlForm _serverAndClient = new CaptureAndPlayCtrlForm();
bool _msgSent = false;
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 cex)
{
// could not connect
_result = false;
return;
}
// connects the client player
_playCtrl.SourceFile = _networkUrl;
} |
Requirements
Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7
See Also