コード例 #1
0
 /// <summary>
 /// Create an instance of http server configuration.
 /// </summary>
 public HttpServerConfig()
 {
     TcpConfig = new TcpServerConfig();
     TcpConfig.ReceiveDataMaxSpeed = TcpServerConfig.NotLimited;
     TcpConfig.SendDataMaxSpeed    = TcpServerConfig.NotLimited;
     TcpConfig.EnableKeepAlive     = false;
 }
コード例 #2
0
        private Boolean ExecuteStartState(ref ITcpServer server, Object[] args)
        {
            const String serverStartFormat = "=================> Server was started on {0} : {1}";
            Boolean      result;

            if (args.Length >= 2 && (args[0] != null && args[1] != null))
            {
                String          ipAddress    = args[0] as String;
                UInt16          port         = Convert.ToUInt16(args[1]);
                String          settingsFile = args[2] as String;
                String          scriptFile   = args[3] as String;
                TcpServerConfig config       = settingsFile != null?TcpServerConfigBuilder.Build(settingsFile) : null;

                if (server == null || scriptFile != null)
                {
                    server = new FlexibleTcpServer(scriptFile, ipAddress, port, _logger, false, config);
                }
                result = server.Start(ipAddress, port);
                if (result)
                {
                    System.Console.WriteLine(serverStartFormat, ipAddress, port);
                }
                _currentState = result ? MachineState.Started : _currentState;
                return(result);
            }
            result = server.Start();
            if (result)
            {
                System.Console.WriteLine("=================> Server was started");
            }
            _currentState = result ? MachineState.Started : _currentState;
            return(result);
        }
コード例 #3
0
ファイル: TcpServer.cs プロジェクト: luohuazhiyu/sunsocket
 //构造函数
 public TcpServer(TcpServerConfig config, ILoger loger)
 {
     this.Config = config;
     endPoint = new IPEndPoint(IPAddress.Parse(config.IP), config.Port);
     this.sessionPool = new TcpSessionPool();
     this.sessionPool.TcpServer = this;
     this.Loger = loger;
 }
コード例 #4
0
ファイル: TcpServer.cs プロジェクト: ciker/GrapeSocket
 //构造函数
 public TcpServer(TcpServerConfig config)
 {
     this.Config                = config;
     endPoint                   = new IPEndPoint(IPAddress.Parse(config.IP), config.Port);
     this.sessionPool           = new TcpSessionPool();
     this.sessionPool.TcpServer = this;
     this.Loger                 = GetLoger();
 }
コード例 #5
0
        public void TestBuildReadPartialConfig()
        {
            TcpServerConfig expectedConfig = new TcpServerConfig();

            expectedConfig.ParallelTask       = 256;
            expectedConfig.ServerCloseTimeout = 7000;
            ReadConfigAndCheck(PartialSettingsFile, expectedConfig);
        }
コード例 #6
0
        private Boolean ExecuteStartState(ref ITcpServer server, Object[] args)
        {
            const String serverStartFormat = "=================> Server was started on {0} : {1}";
            Boolean      result;

            if (args.Length >= 2 && (args[0] != null && args[1] != null))
            {
                String ipAddress = args[0] as String;
                if (!String.IsNullOrEmpty(ipAddress))
                {
                    _ipAddress = ipAddress;
                }
                UInt16 port = Convert.ToUInt16(args[1]);
                _port = port;
                String settingsFile = args[2] as String;
                String scriptFile   = args[3] as String;
                if (!String.IsNullOrEmpty(scriptFile))
                {
                    _scriptFile = scriptFile;
                }
                String          compilerOptionFile = args[4] as String;
                CompilerOptions compilerOptions    = compilerOptionFile != null?CompilerOptionsBuilder.Build(compilerOptionFile) : null;

                TcpServerConfig config = settingsFile != null?TcpServerConfigBuilder.Build(settingsFile) : null;

                if (compilerOptions != null)
                {
                    _compilerOptions = compilerOptions;
                }
                if (config != null)
                {
                    _config = config;
                }
                if (server == null || scriptFile != null || compilerOptionFile != null)
                {
                    //System.Console.WriteLine("tcp server re-creation....");
                    server = new FlexibleTcpServer(_scriptFile, _ipAddress, _port, _compilerOptions, _logger, false, _config);
                }
                result = server.Start(_ipAddress, _port);
                if (result)
                {
                    System.Console.WriteLine(serverStartFormat, _ipAddress, _port);
                }
                _currentState = result ? MachineState.Started : _currentState;
                return(result);
            }
            server = new FlexibleTcpServer(_scriptFile, _ipAddress, _port, _compilerOptions, _logger, false, _config);
            result = server.Start();
            if (result)
            {
                System.Console.WriteLine("=================> Server was started");
            }
            _currentState = result ? MachineState.Started : _currentState;
            return(result);
        }
コード例 #7
0
 static public int get_timeOut(IntPtr l)
 {
     try {
         TcpServerConfig self = (TcpServerConfig)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.timeOut);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #8
0
 static public int constructor(IntPtr l)
 {
     try {
         TcpServerConfig o;
         o = new TcpServerConfig();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: luohuazhiyu/sunsocket
 static void Main(string[] args)
 {
     TcpServerConfig configOne = new TcpServerConfig { ServerId=1,Name = "one", IP = "127.0.0.1", Port = 8088,BufferSize = 1024,MaxFixedBufferPoolSize=1024*4, MaxConnections = 8000 };
     MyServer listener = new MyServer(configOne, loger);
     listener.Start();
     MonitorConfig monitorConfig = new MonitorConfig();
     monitorConfig.WorkDelayMilliseconds = 10000;
     monitorConfig.TimeoutMilliseconds = 10000;
     MyMonitor monitor = new MyMonitor(monitorConfig,3000);
     monitor.AddServer(listener);
     monitor.Start();
     Console.WriteLine("服务器已启动");
     Console.ReadLine();
 }
コード例 #10
0
 static public int set_netFunc(IntPtr l)
 {
     try {
         TcpServerConfig  self = (TcpServerConfig)checkSelf(l);
         SLua.LuaFunction v;
         checkType(l, 2, out v);
         self.netFunc = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #11
0
 static public int set_ipPort(IntPtr l)
 {
     try {
         TcpServerConfig self = (TcpServerConfig)checkSelf(l);
         System.Int32    v;
         checkType(l, 2, out v);
         self.ipPort = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #12
0
        private void ReadConfigAndCheck(String configFile, TcpServerConfig expectedConfig)
        {
            TcpServerConfig actualConfig = TcpServerConfigBuilder.Build(configFile);

            Assert.AreEqual(expectedConfig.ChunkSize, actualConfig.ChunkSize, "ChunkSize");
            Assert.AreEqual(expectedConfig.ClientBufferSize, actualConfig.ClientBufferSize, "ClientBufferSize");
            Assert.AreEqual(expectedConfig.ClientConnectAttempts, actualConfig.ClientConnectAttempts, "ClientConnectAttempts");
            Assert.AreEqual(expectedConfig.ClientConnectTimeout, actualConfig.ClientConnectTimeout, "ClientConnectTimeout");
            Assert.AreEqual(expectedConfig.ClientInactivityTime, actualConfig.ClientInactivityTime, "ClientInactivityTime");
            Assert.AreEqual(expectedConfig.ClientReadAttempts, actualConfig.ClientReadAttempts, "ClientReadAttempts");
            Assert.AreEqual(expectedConfig.ParallelTask, actualConfig.ParallelTask, "ParallelTask");
            Assert.AreEqual(expectedConfig.ReadTimeout, actualConfig.ReadTimeout, "ReadTimeout");
            Assert.AreEqual(expectedConfig.ServerCloseTimeout, actualConfig.ServerCloseTimeout, "ServerCloseTimeout");
            Assert.AreEqual(expectedConfig.WriteTimeout, actualConfig.WriteTimeout, "WriteTimeout");
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: ciker/GrapeSocket
        static void Main(string[] args)
        {
            TcpServerConfig configOne = new TcpServerConfig {
                ServerId = 1, Name = "one", IP = "127.0.0.1", Port = 8088, BufferSize = 1024, MaxFixedBufferPoolSize = 1024 * 4, MaxConnections = 8000
            };
            MyServer listener = new MyServer(configOne, loger);

            listener.Start();
            // MonitorConfig monitorConfig = new MonitorConfig();
            // monitorConfig.WorkDelayMilliseconds = 10000;
            // monitorConfig.TimeoutMilliseconds = 10000;
            // MyMonitor monitor = new MyMonitor(monitorConfig, 3000);
            // monitor.AddServer(listener);
            // monitor.Start();
            Console.WriteLine("服务器已启动");
            Console.ReadLine();
        }
コード例 #14
0
        public static IList <String> GetConfigStrings(TcpServerConfig config)
        {
            IList <String> strings = new List <String>();

            strings.Add(String.Format(ConnectTimeoutTemplate, config.ClientConnectTimeout));
            strings.Add(String.Format(ReadTimeoutTemplate, config.ReadTimeout));
            strings.Add(String.Format(WriteTimeoutTemplate, config.WriteTimeout));
            strings.Add(String.Format(ServerCloseTimeoutTemplate, config.ServerCloseTimeout));
            strings.Add(String.Format(ClientInactivityTimeTemplate, config.ClientInactivityTime));

            strings.Add(String.Format(ConnectAttemptsTemplate, config.ClientConnectAttempts));
            strings.Add(String.Format(ReadAttemptsTemplate, config.ClientReadAttempts));

            strings.Add(String.Format(ParallelTasksTemplate, config.ParallelTask));
            strings.Add(String.Format(ClientBufferSizeTemplate, config.ClientBufferSize));
            return(strings);
        }
コード例 #15
0
        static void Main(string[] args)
        {
            var loger  = new Loger();
            var config = new TcpServerConfig();

            config.BufferSize     = 1024 * 4;
            config.MaxConnections = 40000;
            Framework.Listener listener = new Framework.Listener(config, new ServerEndPoint()
            {
                Name = "one", IP = "127.0.0.1", Port = 8088
            }, loger);
            listener.AsyncServer.OnReceived += ReceiveCommond;
            listener.Start();
            Framework.Listener listenerOne = new Framework.Listener(config, new ServerEndPoint()
            {
                Name = "one", IP = "127.0.0.1", Port = 9988
            }, loger);
            listenerOne.AsyncServer.OnReceived += ReceiveCommond;
            listenerOne.Start();
            Console.WriteLine("服务器已启动");
            Console.ReadLine();
        }
コード例 #16
0
        public static TcpServerConfig Build(String serverConfig)
        {
            if (String.IsNullOrEmpty(serverConfig))
            {
                throw new ArgumentNullException("serverConfig");
            }
            if (!File.Exists(serverConfig))
            {
                throw new ApplicationException("Config file does not exists");
            }
            IList <String> content = File.ReadAllLines(serverConfig).Select(line => line.Trim().ToLower())
                                     .Where(line => !String.IsNullOrEmpty(line))
                                     .Where(line => !line.StartsWith(CommentarySymbol))
                                     .ToList();
            TcpServerConfig config = new TcpServerConfig();
            Int32           value  = GetConfigurationValue(content, ParallelTaskKey);

            if (value != -1)                     // otherwise we using default value
            {
                config.ParallelTask = value;
            }
            value = GetConfigurationValue(content, ClientBufferSizeKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ClientBufferSize = value;
            }
            value = GetConfigurationValue(content, ChunkSizeKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ChunkSize = value;
            }
            value = GetConfigurationValue(content, ClientConnectAttemptsKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ClientConnectAttempts = value;
            }
            value = GetConfigurationValue(content, ClientConnectTimeoutKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ClientConnectTimeout = value;
            }
            value = GetConfigurationValue(content, ClientInactivityTimeKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ClientInactivityTime = value;
            }
            value = GetConfigurationValue(content, ReadTimeoutKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ReadTimeout = value;
            }
            value = GetConfigurationValue(content, WriteTimeoutKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.WriteTimeout = value;
            }
            value = GetConfigurationValue(content, ClientReadAttemptsKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ClientReadAttempts = value;
            }
            value = GetConfigurationValue(content, ServerCloseTimeoutKey);
            if (value != -1)                     // otherwise we using default value
            {
                config.ServerCloseTimeout = value;
            }
            return(config);
        }
コード例 #17
0
 public TimeTcpServer(String ipAddress, UInt16 port = DefaultTimePort, ILog logger = null, Boolean debug = false, TcpServerConfig config = null)
     : base(ipAddress, port, logger, debug, config)
 {
     _task = new Task(ClientProccessor);
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: luohuazhiyu/sunsocket
 public MyServer(TcpServerConfig config, ILoger loger) : base(config, loger)
 { }
コード例 #19
0
ファイル: TcpIpTestForm.cs プロジェクト: marcellus/fivemen
        private void button1_Click(object sender, EventArgs e)
        {
            Form form = new TcpServerConfig();

            form.ShowDialog();
        }
コード例 #20
0
 public static ITcpServer Create(String ipAddress, UInt16 port, String serverScriptFile, ILog logger = null, TcpServerConfig config = null)
 {
     return(new FlexibleTcpServer(serverScriptFile, ipAddress, port, logger, false, config));
 }
コード例 #21
0
        public void TestBuildReadFullConfigs()
        {
            TcpServerConfig expectedConfig = new TcpServerConfig(1000, 200, 1000, 2000, 120, 4, 8, 256, 65535, 4096);

            ReadConfigAndCheck(FullSettingsFile, expectedConfig);
        }
コード例 #22
0
 public static IServer CreateTcpServer(TcpServerConfig config)
 {
     return(new TcpServer(config));
 }
コード例 #23
0
ファイル: XTcpServer.cs プロジェクト: oathx/myactx
 /// <summary>
 /// Startup this instance.
 /// </summary>
 public virtual void     Startup(TcpServerConfig serverConfig)
 {
     config  = serverConfig;
     netFunc = config.netFunc;
 }
コード例 #24
0
ファイル: Program.cs プロジェクト: tim-xia/sunsocket
 public MyServer(TcpServerConfig config, ILoger loger) : base(config, loger)
 {
 }
コード例 #25
0
 public EchoTcpServer(String ipAddress, UInt16 port = DefaultEchoPort, ILog logger = null, Boolean debug = false, TcpServerConfig config = null)
     : base(ipAddress, port, logger, debug, config)
 {
     AddHandler(new TcpClientHandlerInfo(Guid.NewGuid()), EchoTcpClientHandler.Handle);
 }
コード例 #26
0
ファイル: Program.cs プロジェクト: ciker/GrapeSocket
 public MyServer(TcpServerConfig config, ILoger loger) : base(config)
 {
     this.logger = loger;
 }