Adds an IConnectionListener that receives status events
about the state of StreamLink's connection to the server.
![](../icons/collapse_all.gif)
C# | Visual Basic | Visual C++ |
void AddConnectionListener( IConnectionListener listener )
Sub AddConnectionListener ( _ listener As IConnectionListener _ )
void AddConnectionListener( IConnectionListener^ listener )
![](../icons/collapse_all.gif)
- listener (IConnectionListener)
- The IConnectionListener to be registered with IStreamLinkProvider.
![](../icons/collapse_all.gif)
Once registered, the IConnectionListener will receive event updates whenever the connection status has changed (for details see the description of IConnectionListener).
![](../icons/collapse_all.gif)
![](../icons/CopyCode.gif)
using System; using System.Collections.Generic; using System.Text; using Caplin.StreamLink; using Caplin.StreamLink.Authentication; namespace StreamLinkExamples.Basics { /// <summary> /// Example of an internal class that implements IConnectionListener /// and of how to use the IConnectionListener class. /// </summary> public class AddingAConnectionListener { /// <summary> /// Shows how to create a StreamLink and a connection listener /// and add the listener for connection events. /// </summary> public static void AddingAConnectionListenerExample() { StreamLink myStreamLink = new StreamLink(); myStreamLink.CredentialsProvider = new PasswordCredentialsProvider("admin", "admin"); IConnectionListener connectionListener = new ExampleConnectionListener(); // Add the new connection listener instance so that it // receives connection related events. myStreamLink.StreamLinkProvider.AddConnectionListener( connectionListener); } /// <summary> /// Example of a class the implements the IConnectionListener. /// </summary> private class ExampleConnectionListener : IConnectionListener { #region IConnectionListener Members // Just log the status update public void ConnectionStatusUpdated(IConnectionStatusEvent ev) { Console.WriteLine("Connection Status Updated: " + ev.Status.ToString()); } // Just log the source update public void SourceStatusUpdated(ISourceStatusEvent ev) { Console.WriteLine( string.Format("Source Status Updated: {0} {1}", ev.Name, ev.Status.ToString())); } // Just log the service update public void ServiceStatusUpdated(IServiceStatusEvent ev) { Console.WriteLine( string.Format("Service Status Updated: {0} {1}", ev.Name, ev.Status.ToString())); } #endregion } } }