Click or drag to resize

ServerChannel Class

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

Namespace:  OBCOM.NetSwitchLib.Servers
Assembly:  OBCOM.NetSwitchLib (in OBCOM.NetSwitchLib.dll) Version: 1.48.7760.35650 (1.48.7760.35650)
Syntax
public class ServerChannel : ChannelBase, 
	IMailServices

The ServerChannel type exposes the following members.

Constructors
  NameDescription
Public methodServerChannel
Constructs a new ServerChannel instance.
Top
Properties
  NameDescription
Public propertyArguments
Gets the command arguments supplied to the Main method of this channel.
Public propertyIdleTimeout
Gets or sets the idle timeout of this server channel (milliseconds).
Public propertyIsConnected
Gets a value that indicates whether this channel is connected.
(Inherited from ChannelBase.)
Public propertyIsExecuting
Gets a value that indicates if this channel is executing.
Public propertyIsSecure
Gets a value that indicates whether this channel is secure
(Inherited from ChannelBase.)
Public propertyIsServerThread
Gets a value that indicates if running in the server thread.
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 to which this channel is connected.
Public propertySwitchReplyTimeout
Gets or sets the maximum time to wait for a NetSwitch reply (milliseconds).
Public propertySwitchURI
Gets the URI of the NetSwitch to which this channel is connected.
Public propertySwitchVersion
Gets the version of the NetSwitch to which this channel is connected.
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 propertyUniqueName
Gets the unique name of this channel.
Public propertyVersion
Gets a string with the implementation version of this channel.
Top
Methods
  NameDescription
Public methodAddRequestHandler
Registers a handler identified by the supplied name.
Public methodCancelTimer
Public methodClearStatistics
Clears the statistics of a specific service or all services.
Protected methodConnect
Connects this channel to serverURI.
(Inherited from ChannelBase.)
Public methodDecodePassword
Decodes an encoded password using supplied arguments.
Public methodDefineHistogram
Defines the execution histogram of a specific service or all services.
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 methodExecute(String)
Starts the execution of this ServerChannel.
Public methodExecute(String, IServerContext)
Starts the execution of this ServerChannel.
Public methodExecute(String, Properties, IServerContext)
Starts the execution of this ServerChannel.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetProperties
Returns all the properties of this channel.
Public methodGetProperty(String)
Gets the value of a property indexed by the specified name.
Public methodGetProperty(String, String)
Gets the value of a property indexed by the specified name.
Public methodGetStatistics
Returns a list with statistics of a specific service or all services.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodHandleIdle
Called when a idle event occurs.
Protected methodHandleInbound
Handles an inbound message received by this channel.
(Overrides ChannelBaseHandleInbound(Message).)
Protected methodHandleInitialize
Called just after this channel connects to the NetSwitch server.
Protected methodHandleReinitialize
Called just after a console REINIT command is executed.
Protected methodHandleStop
Called when a stop message is received.
Protected methodHandleTimer
Called when a timer event occurs.
Public methodInform
Logs an information message.
(Inherited from ChannelBase.)
Protected methodLogRequestError
Logs the error that was thrown while processing a request message.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRemoveRequestHandler
Unregisters the request handler identified by supplied name.
Protected methodReplyCompleted
Called after an asynchronous reply message has been successfully processed by a ReplyHandler method.
Protected methodReplyError
Called after an exception is thrown while processing an asynchronous reply message.
Protected methodReplyReceived
Called after an asynchronous reply message has been received and before it is processed by a ReplyHandler method.
Protected methodRequestCompleted
Called after a request message has been successfully processed by a RequestHandler method.
Protected methodRequestError
Called after an exception is thrown while processing a request message.
Protected methodRequestReceived
Called after a request message has been received and before it is processed by a RequestHandler method.
Public methodRunAsyncTaskT
Executes the supplied task in a separate thread.
Public methodRunLater
Runs an action on the server's thread at some time in the future.
Public methodSendMail(String, String)
Sends a mail message using the "default" SMTP mail session.
Public methodSendMail(String, String, String)
Sends a mail message using the specified SMTP mail session.
Public methodSendMessage
Sends a request message to a destination.
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, ReplyHandler)
Sends a request message to a destination and then calls handler when the asynchronous reply is received.
Public methodSendRequest(String, Object, Int32)
Sends a request message to a destination and then blocks waiting for the reply until timeout.
Public methodSendRequest(String, Object, ReplyHandler, Int32)
Sends a request message to a destination and then calls handler when the asynchronous reply is received.
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 methodStartTimer
Schedules the execution of the HandleTimer method at regular intervals.
Public methodStop
Stops the execution of this server channel.
Public methodStop(String)
Stops the execution of this server channel with a reason.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodWarning
Logs a warning message.
(Inherited from ChannelBase.)
Protected methodWriteLog
Writes the supplied log message with specified level.
(Inherited from ChannelBase.)
Public methodWriteMessage
Writes the message to this channel.
(Inherited from ChannelBase.)
Top
Remarks

Once the communcation is established with the NetServer, the application is able to receive transaction requests, send unsolicited data, and provide other services to the clients of a NetSwitch server.

A server application is constructed by extending the ServerChannel class and then overriding the ProcessXXXXXXX methods. For example, the ProcessTransaction method is called each time the server receives a transaction request from an NetServer client application (see ClientChannel for details about building NetServer client applications).

The following table describes the properties of a ServerChannel:

PropertyDescriptionTypeDefault
netswitch.uriProtocol, address and port of the NetSwitch serverstringNETSWITCH
netswitch.passwordPassword use to authenticate the server channelstringnone
netswitch.server.keep.aliveEnable or disable the socket SO_KEEPALIVE optionboolfalse
netswitch.server.reader.buffer.freeFree size of the reader buffer (bytes)int4096
netswitch.server.reader.buffer.maxMaximum size of the reader buffer (bytes)int0 (unbounded)
netswitch.server.reader.buffer.minMinimum size of the reader buffer (bytes)int8192
netswitch.server.reader.buffer.warnWarning size of the reader buffer (bytes)int8192
netswitch.server.reply.timeoutMaximum time to wait for a NetSwitch reply (milliseconds)int800
netswitch.server.tcp.nodelayEnable or disable the socket TCP_NODELAY optionbooltrue
netswitch.server.traceTrace inbound and outbound messages (for debugging)boolfalse
netswitch.server.trust.storePath of the JKS trust store file used for SSL connectionsstringnone
netswitch.server.writer.queue.sizeMaximum size of the writer queue (messages)int64
Examples

The following example uses ServerChannel to implement a server application named "SampleServer". This server is very simple: it just sends a reply to Hello service requests:

using OBCOM.NetSwitchLib.Servers;

public class SampleServer : ServerChannel
{
    // Called after SampleServer connects to NetSwitch.
    protected override void HandleInitialize()
    {
         AddRequestHandler("Hello", HelloService);
    }

    // Called when a <c>Hello</c> service request is received.
    private void HelloService(RequestEvent request)
    {
         request.SendReply($"Hello to you too, {request.Message.Text}");
    }

    // Startup method of SampleServer.
    public static void Main(string[] args)
    {
        new SampleServer().Execute("SAMPLE_SERVER");
    }
}
See Also