←Select platform

FirstConnection Property

Summary

Gets the object for the first connection in the list of available connections to the server.

Syntax

C#
VB
C++
[DispIdAttribute(2)] 
Lmnetsnk.ILMNetSnkConnection FirstConnection {get;} 
             
  
<DispIdAttribute(2)> 
ReadOnly Property FirstConnection As Lmnetsnk.ILMNetSnkConnection 
             
[DispIdAttribute(2)] 
property Lmnetsnk.ILMNetSnkConnection^ FirstConnection { 
   Lmnetsnk.ILMNetSnkConnection^ get(); 
} 
             

Property Value

The ILMNetSnkConnection object that represents the first connection in the list of available connections to the server.

Remarks

If the property succeeds, you need to release the returned object by calling Marshal.ReleaseComObject.

Example

C#
VB
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
public bool _result = false; 
public CaptureAndPlayCtrlForm _serverAndClient = new CaptureAndPlayCtrlForm(); 
 
CaptureCtrl _captureCtrl; 
PlayCtrl _playCtrl; 
LMNetMux _pMux; 
LMNetSnk _pSink; 
 
const string _networkUrl = @"ltsf://127.0.0.1:27015"; // network stream url 
const string _networkAuthenticatedUrl = @"ltsf://User1:P99999@127.0.0.1:27015"; // network stream url 
const string TestMessage = "LEAD NETWORK"; 
 
public void RequireLoginExample() 
{ 
   // 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)) 
      { 
         // here we will only capture 15 seconds for this example. 
         // in a real application, you would not normally want to  
         // set the time limit for capture. 
         _captureCtrl.TimeLimit = 15; 
         _captureCtrl.UseTimeLimit = true; 
 
         // enable preview 
         _captureCtrl.Preview = true; 
 
         // subscribe to the started event for this example 
         // we will connect a client after the capture starts 
         _captureCtrl.Started += new EventHandler(CaptureCtrl_Started); 
 
         // subcribe to the media event for the player 
         _playCtrl.MediaEvent += new MediaEventHandler(PlayCtrl_MediaEvent); 
 
         // ready the capture graph in order to get the LNMetMux instance 
         _captureCtrl.ReadyCapture(CaptureMode.Video); 
 
         // get the network multiplexer reference 
         _pMux = _captureCtrl.GetSubObject(CaptureObject.TargetFilter) as LMNetMux; 
 
         if (_pMux != null) 
         { 
            // set some mux settings 
            _pMux.LiveSource = true; 
         } 
 
         // get the network sink reference 
         _pSink = _captureCtrl.GetSubObject(CaptureObject.Sink) as LMNetSnk; 
 
         if (_pSink != null) 
         { 
            // set some mux settings 
            _pSink.RequireLogin = true; 
            _pSink.UseEncryption = LMNetSnkLib.NetSnk_Encryption.NetSnk_Encryption_None; 
 
            // clear all user registrations 
            _pSink.RemoveAllUsers(); 
 
            // setup up user logins 
            AddModifyUsers(); 
 
            // enumeration users 
            EnumerateUsers(); 
 
            // add a restriction 
            AddRestriction(); 
 
            // test timer for connection checking 
            _serverAndClient.TestTimer.Interval = 10000; 
            _serverAndClient.TestTimer.Start(); 
            _serverAndClient.TestTimer.Tick += new EventHandler(ConnectionChecker); 
         } 
 
         // 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(); 
         } 
 
         // release the mux and demux COM objects 
         if (_pMux != null) 
            Marshal.ReleaseComObject(_pMux); 
 
         if (_pSink != null) 
            Marshal.ReleaseComObject(_pSink); 
      } 
   } 
   catch (Exception ex) 
   { 
      _result = false; 
   } 
} 
 
private void AddModifyUsers() 
{ 
   // early out if we could not get the sink interface 
   if (_pSink == null) 
      return; 
 
   // get the current connection list version 
   int oldVers = _pSink.ConnectionVersion; 
 
   // add a user 
   _pSink.AddUser("User1", "P12345"); 
 
   // get the current connection list version 
   int newVers = _pSink.ConnectionVersion; 
 
   // add another user 
   _pSink.AddUser("User2", "P67890"); 
 
   // find a user 
   int user1Id = _pSink.FindUser("User1"); 
 
   // set user 1's password -- was set above in the AddUser call 
   // but we will change it here for demonstration purposes 
   _pSink.SetPassword(user1Id, "P99999"); 
 
   // remove User2 from the registered users list  
   int user2Id = _pSink.FindUser("User2"); 
   _pSink.RemoveUser(user2Id); 
} 
 
private void EnumerateUsers() 
{ 
   // get the current user count 
   int userCount = _pSink.UserCount; 
 
   // verify that we have two users now 
   _result = (userCount == 1); 
 
   // demostrate enumeration registered users 
   for (int i = 0; i < userCount; i++) 
   { 
      // do something with user names and passwords 
      string userName = _pSink.GetUsername(i); 
      string passWord = _pSink.GetPassword(i); 
   } 
 
} 
 
private void AddRestriction() 
{ 
   // add a restriction to the client which has the IP = 10.0.0.5 
   // this will not allow a connection from this address.  
 
   // get number of restrictions 
   int oldRestCount = _pSink.RestrictionCount; 
 
   // Number of restrictions we have.  
   int restrictCount = _pSink.AddRestriction("10.0.0.5"); 
 
   // get number of restrictions 
   int newRestCount = _pSink.RestrictionCount; 
 
   // verify that we have a new restriction count 
   _result &= (oldRestCount != newRestCount); 
 
   // enumeration restrictions (demonstration purposes) 
   for (int i = 0; i < restrictCount; i++) 
   { 
      string restAddress = _pSink.GetRestriction(i); 
      // do something with Restriction 
   } 
 
   // find our restriction we added above 
   int restriction = _pSink.FindRestriction("10.0.0.5"); 
 
   // remove it 
   _pSink.RemoveRestriction(restriction); 
 
   // remove all restrictions (demonstration purposes) 
   _pSink.RemoveAllRestrictions(); 
} 
 
void CaptureCtrl_Started(object sender, EventArgs e) 
{ 
   StartClient(); 
} 
 
private void StartClient() 
{ 
   try 
   { 
      // connect a client 
      _playCtrl.SourceFile = _networkAuthenticatedUrl; 
   } 
   catch (Exception ex) 
   { 
      _result = false; 
      Console.WriteLine("Player (Client) Exception: {0}", ex.Message); 
   } 
} 
 
void ConnectionChecker(object sender, EventArgs e) 
{ 
   _serverAndClient.TestTimer.Stop(); 
 
   // get number of users connected to the server 
   int connCount = _pSink.ConnectionCount; 
 
   // get the first connection (demonstration purposes) 
   ILMNetSnkConnection pcon = _pSink.FindConnection(1); 
   // release it -- it is a COM object you know! 
   Marshal.ReleaseComObject(pcon); 
 
   // get the first connection 
   pcon = _pSink.FirstConnection; 
 
   // check all connections with the server 
   while (pcon != null) 
   { 
      ILMNetSnkConnection pnext = pcon.NextConnection; 
      long id = pcon.ID; 
      string userName = pcon.Username; 
      string connAddr = pcon.Address; 
 
      // check if connection is enabled or not 
      // it should be, we just enabled it above 
      bool enabled = pcon.Enabled; 
 
      // is it connected 
      bool connected = pcon.Connected; 
 
      // check if this connection is disabled 
      // and disconnect it if so 
      if (enabled == false) 
      { 
         // close this connection 
         pcon.Close(); 
      } 
      Marshal.ReleaseComObject(pcon); 
      pcon = pnext; 
   } 
 
   // close all connections (demonstration purposes) 
   _pSink.CloseAll(); 
 
   _serverAndClient.TestTimer.Start(); 
} 
 
private void PlayCtrl_MediaEvent(object sender, MediaEventArgs e) 
{ 
   if (e.eventCode == MediaEventCode.EC_COMPLETE) 
      _result &= true; 
} 
Imports Leadtools 
Imports Leadtools.Multimedia 
Imports LeadtoolsMultimediaExamples.Fixtures 
 
Public _result As Boolean = False 
Public _serverAndClient As CaptureAndPlayCtrlForm = New CaptureAndPlayCtrlForm() 
 
Private _captureCtrl As CaptureCtrl 
Private _playCtrl As PlayCtrl 
Private _pMux As LMNetMux 
Private _pSink As LMNetSnk 
 
Private Const _networkUrl As String = "ltsf://127.0.0.1:27015" ' network stream url 
Private Const _networkAuthenticatedUrl As String = "ltsf://User1:P99999@127.0.0.1:27015" ' network stream url 
Private Const TestMessage As String = "LEAD NETWORK" 
 
Public Sub RequireLoginExample() 
   ' 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 
         ' here we will only capture 15 seconds for this example. 
         ' in a real application, you would not normally want to  
         ' set the time limit for capture. 
         _captureCtrl.TimeLimit = 15 
         _captureCtrl.UseTimeLimit = True 
 
         ' enable preview 
         _captureCtrl.Preview = True 
 
         ' subscribe to the started event for this example 
         ' we will connect a client after the capture starts 
         AddHandler _captureCtrl.Started, AddressOf CaptureCtrl_Started 
 
         ' subscribe to the media event for the player 
         AddHandler _playCtrl.MediaEvent, AddressOf PlayCtrl_MediaEvent 
 
         ' ready the capture graph in order to get the LNMetMux instance 
         _captureCtrl.ReadyCapture(CaptureMode.Video) 
 
         ' get the network multiplexer reference 
         _pMux = TryCast(_captureCtrl.GetSubObject(CaptureObject.TargetFilter), LMNetMux) 
 
         If Not _pMux Is Nothing Then 
            ' set some mux settings 
            _pMux.LiveSource = True 
         End If 
 
         ' get the network sink reference 
         _pSink = TryCast(_captureCtrl.GetSubObject(CaptureObject.Sink), LMNetSnk) 
 
         If Not _pSink Is Nothing Then 
            ' set some mux settings 
            _pSink.RequireLogin = True 
            _pSink.UseEncryption = LMNetSnkLib.NetSnk_Encryption.NetSnk_Encryption_None 
 
            ' clear all user registrations 
            _pSink.RemoveAllUsers() 
 
            ' setup up user logins 
            AddModifyUsers() 
 
            ' enumeration users 
            EnumerateUsers() 
 
            ' add a restriction 
            AddRestriction() 
 
            ' test timer for connection checking 
            _serverAndClient.TestTimer.Interval = 10000 
            _serverAndClient.TestTimer.Start() 
            AddHandler _serverAndClient.TestTimer.Tick, AddressOf ConnectionChecker 
         End If 
 
         ' 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 
 
         ' release the mux and demux COM objects 
         If Not _pMux Is Nothing Then 
            Marshal.ReleaseComObject(_pMux) 
         End If 
 
         If Not _pSink Is Nothing Then 
            Marshal.ReleaseComObject(_pSink) 
         End If 
      End If 
   Catch ex As Exception 
      _result = False 
   End Try 
End Sub 
 
Private Sub AddModifyUsers() 
   ' early out if we could not get the sink interface 
   If _pSink Is Nothing Then 
      Return 
   End If 
 
   ' get the current connection list version 
   Dim oldVers As Integer = _pSink.ConnectionVersion 
 
   ' add a user 
   _pSink.AddUser("User1", "P12345") 
 
   ' get the current connection list version 
   Dim newVers As Integer = _pSink.ConnectionVersion 
 
   ' add another user 
   _pSink.AddUser("User2", "P67890") 
 
   ' find a user 
   Dim user1Id As Integer = _pSink.FindUser("User1") 
 
   ' set user 1's password -- was set above in the AddUser call 
   ' but we will change it here for demonstration purposes 
   _pSink.SetPassword(user1Id, "P99999") 
 
   ' remove User2 from the registered users list  
   Dim user2Id As Integer = _pSink.FindUser("User2") 
   _pSink.RemoveUser(user2Id) 
End Sub 
 
Private Sub EnumerateUsers() 
   ' get the current user count 
   Dim userCount As Integer = _pSink.UserCount 
 
   ' verify that we have two users now 
   _result = (userCount = 1) 
 
   ' demonstrate enumeration registered users 
   Dim i As Integer = 0 
   Do While i < userCount 
      ' do something with user names and passwords 
      Dim userName As String = _pSink.GetUsername(i) 
      Dim passWord As String = _pSink.GetPassword(i) 
      i += 1 
   Loop 
 
End Sub 
 
Private Sub AddRestriction() 
   ' add a restriction to the client which has the IP = 10.0.0.5 
   ' this will not allow a connection from this address.  
 
   ' get number of restrictions 
   Dim oldRestCount As Integer = _pSink.RestrictionCount 
 
   ' Number of restrictions we have.  
   Dim restrictCount As Integer = _pSink.AddRestriction("10.0.0.5") 
 
   ' get number of restrictions 
   Dim newRestCount As Integer = _pSink.RestrictionCount 
 
   ' verify that we have a new restriction count 
   _result = _result And (oldRestCount <> newRestCount) 
 
   ' enumeration restrictions (demonstration purposes) 
   Dim i As Integer = 0 
   Do While i < restrictCount 
      Dim restAddress As String = _pSink.GetRestriction(i) 
      ' do something with Restriction 
      i += 1 
   Loop 
 
   ' find our restriction we added above 
   Dim restriction As Integer = _pSink.FindRestriction("10.0.0.5") 
 
   ' remove it 
   _pSink.RemoveRestriction(restriction) 
 
   ' remove all restrictions (demonstration purposes) 
   _pSink.RemoveAllRestrictions() 
End Sub 
 
Private Sub CaptureCtrl_Started(ByVal sender As Object, ByVal e As EventArgs) 
   StartClient() 
End Sub 
 
Private Sub StartClient() 
   Try 
      ' connect a client 
      _playCtrl.SourceFile = _networkAuthenticatedUrl 
   Catch ex As Exception 
      _result = False 
      Console.WriteLine("Player (Client) Exception: {0}", ex.Message) 
   End Try 
End Sub 
 
Private Sub ConnectionChecker(ByVal sender As Object, ByVal e As EventArgs) 
   _serverAndClient.TestTimer.Stop() 
 
   ' get the number of users connected to the server 
   Dim connCount As Integer = _pSink.ConnectionCount 
 
   ' get the first connection (demonstration purposes) 
   Dim pcon As ILMNetSnkConnection = _pSink.FindConnection(1) 
   ' release it -- it is a COM object you know! 
   Marshal.ReleaseComObject(pcon) 
 
   ' get the first connection 
   pcon = _pSink.FirstConnection 
 
   ' check all connections with the server 
   Do While Not pcon Is Nothing 
      Dim pnext As ILMNetSnkConnection = pcon.NextConnection 
      Dim id As Long = pcon.ID 
      Dim userName As String = pcon.Username 
      Dim connAddr As String = pcon.Address 
 
      ' determine whether connection is enabled  
      ' it should be, we just enabled it above 
      Dim enabled As Boolean = pcon.Enabled 
 
      ' is it connected 
      Dim connected As Boolean = pcon.Connected 
 
      ' determine whether connection is disabled 
      ' and disconnect it if so 
      If enabled = False Then 
         ' close this connection 
         pcon.Close() 
      End If 
      Marshal.ReleaseComObject(pcon) 
      pcon = pnext 
   Loop 
 
   ' close all connections (demonstration purposes) 
   _pSink.CloseAll() 
 
   _serverAndClient.TestTimer.Start() 
End Sub 
 
Private Sub PlayCtrl_MediaEvent(ByVal sender As Object, ByVal e As MediaEventArgs) 
   If e.eventCode = MediaEventCode.EC_COMPLETE Then 
      _result = _result And True 
   End If 
End Sub 

Requirements

Target Platforms

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Click or drag to resize