Gets the object of the last connection in the list of available connections to the server.
[DispIdAttribute(3)]Connection LastConnection {get;}
<DispIdAttribute(3)>ReadOnly Property LastConnection As Connection
[DispIdAttribute(3)]property Connection^ LastConnection {Connection^ get();}
The ILMNetSnk.Connection object that represents the last connection in the list of available connections to the server.
If the property succeeds, you should release the returned object by calling Marshal.ReleaseComObject.
Use the LastConnection property to determine which connection is the last connection in the list of available connections to the server.
Use the ConnectionCount property to determine the number of open connections to the server.
Use the NextConnection property to get the next connection object from the list of available connections to the server.
Use the PrevConnection property to get the previous connection object from the list of available connections to the server.
Use the FindConnection Method to get the object of the connection at the specified ID in the list of available connections to the server.
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 urlconst string _networkAuthenticatedUrl = @"ltsf://User1:[email protected]:27015"; // network stream urlconst 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 cameraif (_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 loginsAddModifyUsers();// enumeration usersEnumerateUsers();// add a restrictionAddRestriction();// 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 objectsif (_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 interfaceif (_pSink == null)return;// get the current connection list versionint oldVers = _pSink.ConnectionVersion;// add a user_pSink.AddUser("User1", "P12345");// get the current connection list versionint newVers = _pSink.ConnectionVersion;// add another user_pSink.AddUser("User2", "P67890");// find a userint 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 listint user2Id = _pSink.FindUser("User2");_pSink.RemoveUser(user2Id);}private void EnumerateUsers(){// get the current user countint userCount = _pSink.UserCount;// verify that we have two users now_result = (userCount == 1);// demostrate enumeration registered usersfor (int i = 0; i < userCount; i++){// do something with user names and passwordsstring 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 restrictionsint oldRestCount = _pSink.RestrictionCount;// Number of restrictions we have.int restrictCount = _pSink.AddRestriction("10.0.0.5");// get number of restrictionsint 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 aboveint 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 serverint 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 connectionpcon = _pSink.FirstConnection;// check all connections with the serverwhile (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 abovebool enabled = pcon.Enabled;// is it connectedbool connected = pcon.Connected;// check if this connection is disabled// and disconnect it if soif (enabled == false){// close this connectionpcon.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 LeadtoolsImports Leadtools.MultimediaImports LeadtoolsMultimediaExamples.FixturesPublic _result As Boolean = FalsePublic _serverAndClient As CaptureAndPlayCtrlForm = New CaptureAndPlayCtrlForm()Private _captureCtrl As CaptureCtrlPrivate _playCtrl As PlayCtrlPrivate _pMux As LMNetMuxPrivate _pSink As LMNetSnkPrivate Const _networkUrl As String = "ltsf://127.0.0.1:27015" ' network stream urlPrivate Const _networkAuthenticatedUrl As String = "ltsf://User1:[email protected]:27015" ' network stream urlPrivate Const TestMessage As String = "LEAD NETWORK"Public Sub RequireLoginExample()' reference the capture control_captureCtrl = _serverAndClient.CaptureCtrl' reference the play control_playCtrl = _serverAndClient.PlayCtrlTry' try to find a video cameraIf _captureCtrl.VideoDevices("Logitech") Is Nothing ThenThrow 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 = _networkUrlIf _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 startsAddHandler _captureCtrl.Started, AddressOf CaptureCtrl_Started' subscribe to the media event for the playerAddHandler _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 = TrueEnd 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 loginsAddModifyUsers()' enumeration usersEnumerateUsers()' add a restrictionAddRestriction()' test timer for connection checking_serverAndClient.TestTimer.Interval = 10000_serverAndClient.TestTimer.Start()AddHandler _serverAndClient.TestTimer.Tick, AddressOf ConnectionCheckerEnd 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.RunningApplication.DoEvents()Loop' release the mux and demux COM objectsIf Not _pMux Is Nothing ThenMarshal.ReleaseComObject(_pMux)End IfIf Not _pSink Is Nothing ThenMarshal.ReleaseComObject(_pSink)End IfEnd IfCatch ex As Exception_result = FalseEnd TryEnd SubPrivate Sub AddModifyUsers()' early out if we could not get the sink interfaceIf _pSink Is Nothing ThenReturnEnd If' get the current connection list versionDim oldVers As Integer = _pSink.ConnectionVersion' add a user_pSink.AddUser("User1", "P12345")' get the current connection list versionDim newVers As Integer = _pSink.ConnectionVersion' add another user_pSink.AddUser("User2", "P67890")' find a userDim 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 listDim user2Id As Integer = _pSink.FindUser("User2")_pSink.RemoveUser(user2Id)End SubPrivate Sub EnumerateUsers()' get the current user countDim userCount As Integer = _pSink.UserCount' verify that we have two users now_result = (userCount = 1)' demonstrate enumeration registered usersDim i As Integer = 0Do While i < userCount' do something with user names and passwordsDim userName As String = _pSink.GetUsername(i)Dim passWord As String = _pSink.GetPassword(i)i += 1LoopEnd SubPrivate 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 restrictionsDim oldRestCount As Integer = _pSink.RestrictionCount' Number of restrictions we have.Dim restrictCount As Integer = _pSink.AddRestriction("10.0.0.5")' get number of restrictionsDim 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 = 0Do While i < restrictCountDim restAddress As String = _pSink.GetRestriction(i)' do something with Restrictioni += 1Loop' find our restriction we added aboveDim restriction As Integer = _pSink.FindRestriction("10.0.0.5")' remove it_pSink.RemoveRestriction(restriction)' remove all restrictions (demonstration purposes)_pSink.RemoveAllRestrictions()End SubPrivate Sub CaptureCtrl_Started(ByVal sender As Object, ByVal e As EventArgs)StartClient()End SubPrivate Sub StartClient()Try' connect a client_playCtrl.SourceFile = _networkAuthenticatedUrlCatch ex As Exception_result = FalseConsole.WriteLine("Player (Client) Exception: {0}", ex.Message)End TryEnd SubPrivate Sub ConnectionChecker(ByVal sender As Object, ByVal e As EventArgs)_serverAndClient.TestTimer.Stop()' get the number of users connected to the serverDim 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 connectionpcon = _pSink.FirstConnection' check all connections with the serverDo While Not pcon Is NothingDim pnext As ILMNetSnkConnection = pcon.NextConnectionDim id As Long = pcon.IDDim userName As String = pcon.UsernameDim connAddr As String = pcon.Address' determine whether connection is enabled' it should be, we just enabled it aboveDim enabled As Boolean = pcon.Enabled' is it connectedDim connected As Boolean = pcon.Connected' determine whether connection is disabled' and disconnect it if soIf enabled = False Then' close this connectionpcon.Close()End IfMarshal.ReleaseComObject(pcon)pcon = pnextLoop' close all connections (demonstration purposes)_pSink.CloseAll()_serverAndClient.TestTimer.Start()End SubPrivate Sub PlayCtrl_MediaEvent(ByVal sender As Object, ByVal e As MediaEventArgs)If e.eventCode = MediaEventCode.EC_COMPLETE Then_result = _result And TrueEnd IfEnd Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
