[DispIdAttribute(7)]
bool Connected {get;}
true if the connection is open; otherwise, it is false if the connection is closed.
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)
{
Console.WriteLine(ex.Message);
_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;
}