/// <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; }
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); }
//构造函数 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; }
//构造函数 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(); }
public void TestBuildReadPartialConfig() { TcpServerConfig expectedConfig = new TcpServerConfig(); expectedConfig.ParallelTask = 256; expectedConfig.ServerCloseTimeout = 7000; ReadConfigAndCheck(PartialSettingsFile, expectedConfig); }
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); }
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)); } }
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)); } }
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(); }
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)); } }
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)); } }
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"); }
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(); }
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); }
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(); }
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); }
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); }
public MyServer(TcpServerConfig config, ILoger loger) : base(config, loger) { }
private void button1_Click(object sender, EventArgs e) { Form form = new TcpServerConfig(); form.ShowDialog(); }
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)); }
public void TestBuildReadFullConfigs() { TcpServerConfig expectedConfig = new TcpServerConfig(1000, 200, 1000, 2000, 120, 4, 8, 256, 65535, 4096); ReadConfigAndCheck(FullSettingsFile, expectedConfig); }
public static IServer CreateTcpServer(TcpServerConfig config) { return(new TcpServer(config)); }
/// <summary> /// Startup this instance. /// </summary> public virtual void Startup(TcpServerConfig serverConfig) { config = serverConfig; netFunc = config.netFunc; }
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); }
public MyServer(TcpServerConfig config, ILoger loger) : base(config) { this.logger = loger; }