Exemplo n.º 1
0
        /// <summary>
        /// Load Settings from config.
        /// </summary>
        /// <param name="isServer"></param>
        /// <returns></returns>
        public static TcpSettings[] LoadSettings(bool isServer)
        {
            List <TcpSettings> list = new List <TcpSettings>();

            try
            {
                System.Configuration.Configuration config = NetConfig.GetConfiguration();

                XmlDocument doc = new XmlDocument();
                doc.Load(config.FilePath);

                Netlog.Debug("LoadSettings : " + config.FilePath);

                string xpath = isServer ? "//TcpServerSettings" : "//TcpClientSettings";

                XmlNode root = doc.SelectSingleNode(xpath);

                foreach (XmlNode n in root.ChildNodes)
                {
                    if (n.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }

                    TcpSettings ps = new TcpSettings(n, isServer);
                    list.Add(ps);
                }
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constractor with extra parameters
 /// </summary>
 /// <param name="hostAddress"></param>
 /// <param name="port"></param>
 /// <param name="timeout"></param>
 /// <param name="isAsync"></param>
 protected TcpClient(string hostAddress, int port, int timeout, bool isAsync)
 {
     Settings = new TcpSettings()
     {
         HostName       = hostAddress,
         Address        = hostAddress,
         ConnectTimeout = timeout,
         IsAsync        = isAsync,
         Port           = port
     };
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constractor with arguments
 /// </summary>
 /// <param name="hostAddress"></param>
 /// <param name="port"></param>
 /// <param name="timeout"></param>
 /// <param name="receiveBufferSize"></param>
 /// <param name="sendBufferSize"></param>
 /// <param name="isAsync"></param>
 protected TcpClient(string hostAddress, int port, int timeout, int receiveBufferSize, int sendBufferSize, bool isAsync)
 {
     Settings = new TcpSettings()
     {
         HostName          = hostAddress,
         Address           = hostAddress,
         IsAsync           = isAsync,
         Port              = port,
         ConnectTimeout    = timeout,
         ReceiveBufferSize = receiveBufferSize,
         SendBufferSize    = sendBufferSize
     };
 }
Exemplo n.º 4
0
        public static TcpSettings GetTcpClientSettings(string hostName)
        {
            TcpSettings settings = null;

            if (TcpClientSettingsCache.TryGetValue(hostName, out settings))
            {
                return(settings);
            }
            settings = new TcpSettings(hostName, false);
            if (settings == null)
            {
                throw new Exception("Invalid configuration for tcp client settings with host name:" + hostName);
            }
            TcpClientSettingsCache[hostName] = settings;
            return(settings);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constractor default
 /// </summary>
 protected TcpClient()
 {
     Settings = new TcpSettings();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initialize a new instance of <see cref="TcpClient"/> with given <see cref="TcpSettings"/> settings.
 /// </summary>
 /// <param name="settings"></param>
 protected TcpClient(TcpSettings settings)
 {
     Settings = settings;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Constractor default
 /// </summary>
 protected TcpServer()
 {
     Settings = new TcpSettings();
 }
Exemplo n.º 8
0
 /// <summary>
 /// Constractor using settings.
 /// </summary>
 /// <param name="settings"></param>
 protected TcpServer(TcpSettings settings)
 {
     Settings = settings;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Constractor using host configuration.
 /// </summary>
 /// <param name="configHost"></param>
 protected TcpServer(string configHost)
 {
     Settings = new TcpSettings(configHost, true);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Constractor using hostAddress and port.
 /// </summary>
 /// <param name="hostAddress"></param>
 /// <param name="port"></param>
 protected TcpServer(string hostAddress, int port)
 {
     Settings = new TcpSettings(hostAddress, port);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Constractor with extra parameters
 /// </summary>
 /// <param name="settings"></param>
 public TcpJsonServer(TcpSettings settings)
     : base(settings)
 {
     //LoadRemoteCache();
 }