SuperSocket entry (III)-detailed configuration of interaction between multiple Telnet service instances and service instances, and supersocket-telnet

Source: Internet
Author: User
Tags keep alive

SuperSocket entry (III)-detailed configuration of interaction between multiple Telnet service instances and service instances, and supersocket-telnet
In SuperSocket entry (2), we have briefly learned how to use BootStrap to start the SuperSocket service by configuring the App. config file. Let's take a look at the basic configuration file example in the previous case:

<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <configSections> <! -- Log --> <section name = "log4net" type = "System. Configuration. IgnoreSectionHandler"/> <! -- SocketEngine --> <section name = "superSocket" type = "SuperSocket. SocketEngine. Configuration. SocketServiceConfig, SuperSocket. SocketEngine"/> </configSections> <! -- Service Information Description, name identification in window service mode --> <deleetask> <add key = "ServiceName" value = "SupperSocketService"/> <add key = "ServiceDescription" value = "dawn before dusk after the Socket program "/> </appSettings> <! -- SuperSocket service configuration information serverType is a project service, such as my custom myserver --> <! -- Name: Instance name serverType: instance running AppServer type ip: Listener ipport: Listener port --> <superSocket> <servers> <! -- TextEncoding encoding method "gb2312", "UTF-8" is acii by default --> <server name = "SuperSocketDemo" textEncoding = "gb2312" serverType = "SuperSocketDemo. server. myServer, superSocketDemo "ip =" Any "port =" 2020 "maxConnectionNumber =" 100 "> </server> </servers> </superSocket> <startup> <supportedRuntime version =" v4.0" sku = ". NETFramework, Version = v4.5.2 "/> </startup> </configuration>
App. config

1. Service name:


<Add key = "ServiceName" value = "SupperSocketService"/>

<Add key = "ServiceDescription" value = "Socket program after dawn before dusk"/> </appSettings> This configuration item is used as the name of the SuperSocket system service. If ServiceName is set to SupperSocketService, run InstallService. after the bat batch processing file (Note: The processing file uses supersocket.socketservice.exe cute in the same directory), The SuperSocket system service will be installed in the system under the name of "SupperSocketService. 2. SuperSocket root Configuration<SocketServer loggingMode = "IndependantFile">... </socketServer> parameter details in the root Configuration: LoggingMode value:Same file: multiple server instances share the same log file. The default option is "IndependantFile". Multiple server instances have independent log files. Console: Console log output, which is only valid in Console applications. MaxWorkingThreads: Maximum number of worker threads in the thread pool MinWorkingThreads: Minimum number of worker threads in the thread pool MaxCompletionPortThreads: Maximum number of finished port threads in the thread pool MinCompletionPortThreads: Minimum number of finished port threads in the thread pool 3. server instance Configuration<Servers> <server name = "SuperSocketDemo" textEncoding = "gb2312" serverType = "SuperSocketDemo. server. myServer, SuperSocketDemo "ip =" Any "port =" 2020 "maxConnectionNumber =" 100 "> </server> </servers> server instance configuration details:
  • Name: Server instance name
  • ServiceName: Name of the service that the server instance runs. This name is the name of the node that defines the service running on this server instance.
  • Ip: Specifies the IP address of the server that the socket server listens. Any: Listen to all IPv4 addresses of the local machine; listen to 6any, listen to all IPv6 addresses of the local machine.
  • Port: Specifies the port on which the socket server listens.
  • Mode: Sync: Synchronous mode; Async: asynchronous mode; Udp: Udp
  • Disabled: True or false. Whether to disable the server instance. The default value is no.
  • ReadTimeOut: Timeout value for data reading from the socket. The default value is 0.
  • SendTimeOut: Timeout time for sending data from the socket. The default value is 0.
  • MaxConnectionNumber: Maximum number of client connections allowed. The default value is 100.
  • ReceiveBufferSize: The buffer size used to receive data. The default value is 2048.
  • SendBufferSize: The buffer size of data sent by the user. The default value is 2048.
  • LogCommand: True or false, whether to record the command.
  • ClearIdleSession: True or false. Whether to clear idle sessions. The default value is false.
  • ClearIdleSessionInterval: Interval of clearing idle sessions. The default value is 120, in seconds.
  • IdleSessionTimeOut: Session Timeout time. The default value is 300, in seconds.
  • Security: Empty, Tls, or Ssl3. The transport layer encryption protocol used by the Socket server. The default value is null.
  • MaxCommandLength: Maximum allowed command length. The default value is 1024.
  • DisableSessionSnapshot: Whether to disable session snapshots. The default value is false. (1.4 SP1)
  • SessionSnapshotInterval: The time interval for generating session snapshots. The default value is 5, in seconds.
  • KeepAliveTime: Keep alive message sending interval. The default value is 600, in seconds.
  • KeepAliveInterval:The interval at which keep alive failed to retry. The default value is 60, in seconds.
4. multi-server instance ConfigurationSuperSocket supports running multiple server instances in the same program to listen to different IP addresses or ports. You only need to add two server nodes in the configuration file and set different instance names and IP port combinations. <Servers> <server name = "MyServerA" serviceName = "SupperSocketServiceA" ip = "Any" port = "2016"> </server> <server name = "MyServerB" serviceName =" supperSocketServiceB "ip =" Any "port =" 2017 "> </server> <services> <service name =" SupperSocketServiceA "type =" SuperSocketDemo. server. myServerA, SuperSocketDemo. supperSocketServiceA "/> <service name =" SupperSocketServiceB "type =" SuperSocketDemo. server. myServerB, SuperS OcketDemo. SupperSocketServiceB "/> </services> service configuration name: name of the service definition, that is, the name of the server instance node serviceName. Type: the complete name of the service corresponding to the MyServer type. In some cases, two server instances are required for interaction. For example, the client C1 on MyServerA forwards messages to the client C2 on MyServerB, so that MyServerA needs to receive the command C1 and then forward the messages to the client C2 through MyServerB. In the OnStartup method of MyServerA, you can use the GetServerByName (string name) method of SocketServerManager to get the server instance name:
public class MyServerA : AppServer{private IDespatchServer m_DespatchServer; protected override void OnStartup(){m_DespatchServer = SocketServerManager.GetServerByName("ServerB") as IDespatchServer;base.OnStartup();} internal void DespatchMessage(string targetSessionKey, string message){m_DespatchServer.DispatchMessage(targetSessionKey, message);}}
MyServerA class
public class MyServerB : AppServer, IDespatchServer{public void DispatchMessage(string sessionKey, string message){var session = GetAppSessionByIndentityKey(sessionKey);if (session == null)return; session.SendResponse(message);}}}
MyServerB type
interface IDespatchServer{void DispatchMessage(string sessionKey, string message);} 
In this way, the IDespatchServer class can send messages to the client of MyServerB by calling the method of MyServerB instance in MyServerA. When using SuperSocket to implement a Socket server, it is inevitable to define some parameters in the configuration file. SuperSocket provides a very simple method for us to define these parameters in the configuration file and then read them in the code. Server Extension Configuration. We will learn about custom attribute fields later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.