Click or drag to resize

ClientChannel Class

Bi-directional client communication channel with a NetSwitch server.
Inheritance Hierarchy

Namespace:  OBCOM.NetSwitchLib.Clients
Assembly:  OBCOM.NetSwitchLib (in OBCOM.NetSwitchLib.dll) Version: 1.48.7760.35650 (1.48.7760.35650)
Syntax
public sealed class ClientChannel : ChannelBase

The ClientChannel type exposes the following members.

Constructors
  NameDescription
Public methodClientChannel
Constructs a new ClientChannel instance.
Top
Properties
  NameDescription
Public propertyIsConnected
Gets a value that indicates whether this channel is connected.
(Inherited from ChannelBase.)
Public propertyIsSecure
Gets a value that indicates whether this channel is secure
(Inherited from ChannelBase.)
Public propertyKeepAlive
Gets or sets a value that indicates whether the KeepAlive option of this channel is active.
(Inherited from ChannelBase.)
Public propertyName
Gets the name of this channel.
Public propertyReaderBufferFreeSize
Gets or sets the free size of the reader buffer (bytes).
(Inherited from ChannelBase.)
Public propertyReaderBufferMaxSize
Gets or sets the maximum size of the reader buffer (bytes).
(Inherited from ChannelBase.)
Public propertyReaderBufferMinSize
Gets or sets the minimum size of the reader buffer (bytes).
(Inherited from ChannelBase.)
Public propertyReaderBufferWarnSize
Gets or sets the warning size of the reader buffer (bytes).
(Inherited from ChannelBase.)
Public propertySwitchName
Gets the name of the NetSwitch server connected to this channel.
Public propertySwitchURI
Gets the connection URI of this channel.
Public propertySwitchVersion
Gets the version of the NetSwitch server connected to this channel.
Public propertyTag
Gets a value that indicates the connection tag of this channel.
(Inherited from ChannelBase.)
Public propertyTcpNoDelay
Gets or sets a value that indicates whether this channel is using the Nagle algorithm.
(Inherited from ChannelBase.)
Public propertyTracing
Gets a value that indicates whether this channel is tracing inbound and outbound messages.
(Inherited from ChannelBase.)
Public propertyTrustStorePass
Gets or sets the password of the PFX/PKCS12 trust store file used to establish secure (SSL/TLS) connections.
(Inherited from ChannelBase.)
Public propertyTrustStorePath
Gets or sets the path of the PFX/PKCS12 trust store file used to establish secure (SSL/TLS) connections.
(Inherited from ChannelBase.)
Public propertyVersion
Gets the implementation version of this channel.
Top
Methods
  NameDescription
Public methodConnect(String, Properties)
Connects this channel to a NetSwitch server using supplied name and props.
Public methodConnect(String, String)
Connects this channel to a NetSwitch server using supplied name and nameOrUri.
Public methodConnect(String, String, String, String)
Connects this channel to a NetSwitch server using supplied name, nameOrUri, username and password.
Public methodDisableMulticast
Disables the reception of multicast messages identified by name. If name has the special value "*", then this method disables the reception of all multicast messages that have been enabled using the EnableMulticast(String, MulticastHandler) method.
Public methodDispose
Dispose managed and unmanaged objects.
(Overrides ChannelBaseDispose.)
Public methodEnableMulticast
Enables the reception of multicast messages identified by name. Multicast messages are generated when particular event occurs (e.g., the price of a stock has reached a certain limit). When a multicast message arrives, the supplied handler is called.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInform
Logs an information message.
(Inherited from ChannelBase.)
Public methodSendMulticast
Sends an multicast message built using the supplied name and data. The message will be dispatched to all client and/or server applications that have enabled the reception of multicast messages with the specified name.
Public methodSendRequest(String, Object)
Sends a request message to a destination and then blocks forever waiting for the reply message.
Public methodSendRequest(String, Object, Int32)
Sends a request message to a destination and then blocks forever waiting for the reply message.
Public methodSevere(String)
Logs an error message.
(Inherited from ChannelBase.)
Public methodSevere(Exception, String)
Logs an error message with associated ex.
(Inherited from ChannelBase.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodWarning
Logs a warning message.
(Inherited from ChannelBase.)
Public methodWriteMessage
Writes the message to this channel.
(Inherited from ChannelBase.)
Top
Events
  NameDescription
Public eventUnexpectedReply
Occurs when an unexpected reply message is received.
Top
Remarks

An application usse a ClientChannel to send transactions, receive multicast data, and request other services from custom made servers (see ServerChannel for details about building custom servers).

The communication channel is established as late as possible. Yet, once established, it is kept running until a system operator executes the "kill client" command in an NetSwitch Console. If the communication channel is lost for any other reason, it is automatically re-established as soon as possible.

In order to maximize reusability and to reduce the number of physical network connections, the ClientChannel communication link is implemented as a shared (multiplexed) channel. For this reason, a client application cannot use a ClientChannel directly, but it has to acquire a LogicalChannel instance using the ExecuteT(ChannelExecutorT) method. It is through this LogicalChannel that the client application communicates with the NetSwitch environment.

The following example uses a ClientChannel named SampleClient to obtain the date from a server called ACASER. This is accomplished by sending a transaction named ACA-TIME to the ACASER server. If an error occurs while processing this transaction, the reply code of the reply message will not be SUCCESS. In this case, an exception is thrown with a message obtained from the Data of the reply message. If successful, the LogicalChannel is released and the server's date is retrieved from a field called ACC_FECHA of the reply message and displayed in the system console.

The following table describes the properties of a ClientChannel:

PropertyDescriptionTypeDefault
netswitch.client.«name».channel.passwordPassword use to authenticate the client channelstringnone
netswitch.client.«name».keep.aliveEnable or disable the socket SO_KEEPALIVE optionboolfalse
netswitch.client.«name».reply.timeoutMaximum time to wait for reply of connect message (milliseconds)int10000
netswitch.client.«name».reader.buffer.freeFree size of the reader buffer (bytes)int4096
netswitch.client.«name».reader.buffer.maxMaximum size of the reader buffer (bytes)int0 (unbounded)
netswitch.client.«name».reader.buffer.minMinimum size of the reader buffer (bytes)int8192
netswitch.client.«name».reader.buffer.warnWarning size of the reader buffer (bytes)int8192
netswitch.client.«name».switch.uriProtocol, address and port of the NetSwitch serverstringNETSWITCH
netswitch.client.«name».tcp.nodelayEnable or disable the socket TCP_NODELAY optionbooltrue
netswitch.client.«name».traceTrace inbound and outbound messages (for debugging)boolfalse
netswitch.client.«name».trust.store.pathPath of the PFX/PKCS12 trust store file used for SSL/TLS connectionsstringnone
netswitch.client.«name».trust.store.passPassword of the PFX/PKCS12 trust store file used for SSL/TLS connectionsstringnone
netswitch.client.«name».user.nameUsername used to login the channel with the NetSwitch serverstringnone
netswitch.client.«name».user.passwordPassword used to login the channel with the NetSwitch serverstringnone
Examples
using OBCOM.NetSwitchLib.Clients;
using OBCOM.NetSwitchLib.Messages;

public class SampleClient
{
    public static void Main(string[] args)
    {
        // Create client channel named "SAMPLE_CLIENT".
        ClientChannel channel = new ClientChannel();
        client.Connect("SAMPLE_CLIENT", "tcp://localhost:10214");

        // Send request to "ACASER" server and check reply status.
        Message reply = client.SendRequest("ACASER.ACA-TIME", null);
        if (reply.Status != Message.SUCCESS)
            throw new Exception(reply.Text);

        // Build a layout message with information returned in reply message.
        LayoutLoader layoutLoader = new LayoutLoader("http://localhost/layouts/*.asp");
        LayoutMessage layoutReply = new LayoutMessage(reply.Text) {
           Layout = layoutLoader.GetLayout(reply.GetLabel(Label.LayoutName))
        };

        // Display date contained in the "ACASER" layout reply message.
        Console.WriteLine($"The date is {layoutReply.GetDate("ACC_FECHA")}");
    }
}
See Also