WriteMessage Method

Summary
Sends a text message to all connected clients.
Syntax
C#
C++/CLI
[DispIdAttribute(4)] 
void WriteMessage(  
   string Message 
) 
[DispIdAttribute(4)] 
void WriteMessage(  
   String^ Message 
)  

Parameters

Message
A System.String containing the message to send to all connected clients.

Remarks

On the client side, the message can be received using ReadMessage.

Example
C#
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
 
public bool _result = false; 
public CaptureAndPlayCtrlForm _serverAndClient = new CaptureAndPlayCtrlForm(); 
 
bool _msgSent = false; 
CaptureCtrl _captureCtrl; 
PlayCtrl _playCtrl; 
LMNetMux _pMux; 
LMNetDmx _pDemux; 
 
const string _networkUrl = @"ltsf://127.0.0.1:27015"; // network stream url 
const string TestMessage = "LEAD NETWORK"; 
 
public void WriteMessageExample() 
{ 
   // 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.Preview = true; 
 
         // subscribe to the started and progress events for this example 
         // we will connect a client after the capture starts 
         // and send a test message after 5 seconds. 
         _captureCtrl.Started += new EventHandler(CaptureCtrl_Started); 
         _captureCtrl.Progress += new ProgressEventHandler(CaptureCtrl_Progress); 
 
         // 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; 
         } 
 
         // 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 (_pDemux != null) 
            Marshal.ReleaseComObject(_pDemux); 
      } 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
} 
 
void CaptureCtrl_Progress(object sender, ProgressEventArgs e) 
{ 
   // for this test we will send a message after  
   // 5 secs of capture time 
   if (e.time > 5000 && !_msgSent) 
   { 
      _pMux.WriteMessage(TestMessage); 
      Console.WriteLine("Server sent message"); 
      _msgSent = true; 
   } 
} 
 
void CaptureCtrl_Started(object sender, EventArgs e) 
{ 
   StartClient(); 
} 
 
private void StartClient() 
{ 
   _playCtrl.SourceFile = _networkUrl; 
   _pDemux = _playCtrl.GetSubObject(PlayObject.Splitter) as LMNetDmx; 
 
   _serverAndClient.TestTimer.Interval = 100; 
   _serverAndClient.TestTimer.Tick += new EventHandler(PlayTimer_Tick); 
   _serverAndClient.TestTimer.Start(); 
} 
 
void PlayTimer_Tick(object sender, EventArgs e) 
{ 
   _serverAndClient.TestTimer.Enabled = false; 
   if (_pDemux != null) 
   { 
      string msg = _pDemux.ReadMessage(); 
 
      // set the result to what we expect 
      if (msg == TestMessage) 
      { 
         _result = true; 
         Console.WriteLine("Client received message"); 
      } 
   } 
   _serverAndClient.TestTimer.Enabled = true; 
} 
Requirements

Target Platforms

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