//[Fact] public void TestConfigureArgumentExceptions() { var server = new SuperSocketServer(); Assert.Throws <ArgumentNullException>("options", () => server.Configure <TextPackageInfo, LinePipelineFilter>(null)); }
protected SuperSocketServer CreateSocketServer <TPackageInfo>(Dictionary <string, string> configDict = null, Action <IAppSession, TPackageInfo> packageHandler = null, IPipelineFilterFactory <TPackageInfo> filterFactory = null) where TPackageInfo : class { if (configDict == null) { configDict = new Dictionary <string, string> { { "serverOptions:name", "TestServer" }, { "serverOptions:listeners:0:ip", "Any" }, { "serverOptions:listeners:0:port", "4040" } }; } var server = new SuperSocketServer(); var services = new ServiceCollection(); var builder = new ConfigurationBuilder().AddInMemoryCollection(configDict); var config = builder.Build(); services.AddLogging(loggingBuilder => loggingBuilder.AddConsole()); RegisterServices(services); var serverOptions = new ServerOptions(); config.GetSection("serverOptions").Bind(serverOptions); Assert.True(server.Configure <TPackageInfo>(serverOptions, services, packageHandler: packageHandler, pipelineFilterFactory: filterFactory)); return(server); }
static SuperSocketServer CreateSocketServer <TPackageInfo, TPipelineFilter>(Dictionary <string, string> configDict = null, Func <IAppSession, TPackageInfo, Task> packageHandler = null) where TPackageInfo : class where TPipelineFilter : IPipelineFilter <TPackageInfo>, new() { if (configDict == null) { configDict = new Dictionary <string, string> { { "serverOptions:name", "TestServer" }, { "serverOptions:listeners:0:ip", "Any" }, { "serverOptions:listeners:0:port", "4040" } }; } var server = new SuperSocketServer(); var services = new ServiceCollection(); var builder = new ConfigurationBuilder().AddInMemoryCollection(configDict); var config = builder.Build(); services.AddLogging(loggingBuilder => loggingBuilder.AddConsole()); var serverOptions = new ServerOptions(); config.GetSection("serverOptions").Bind(serverOptions); server.Configure <TPackageInfo, TPipelineFilter>(serverOptions, services, packageHandler: packageHandler); return(server); }
public void TestConfigure() { var server = new SuperSocketServer(); var dic = new Dictionary <string, string> { { "name", "TestServer" }, { "listeners:0:ip", "Any" }, { "listeners:0:port", "80" }, { "listeners:0:backLog", "100" }, { "listeners:1:ip", "Ipv6Any" }, { "listeners:1:port", "81" } }; var builder = new ConfigurationBuilder().AddInMemoryCollection(dic); var serverOptions = new ServerOptions(); var config = builder.Build(); config.Bind(serverOptions); Assert.True(server.Configure <LinePackageInfo, LinePipelineFilter>(serverOptions)); Assert.Equal("TestServer", server.Name); // Assert.Equal(2, server.Listeners.Length); // Assert.Equal(IPAddress.Any, server.Listeners[0].EndPoint.Address); // Assert.Equal(80, server.Listeners[0].EndPoint.Port); // Assert.Equal(IPAddress.IPv6Any, server.Listeners[1].EndPoint.Address); // Assert.Equal(81, server.Listeners[1].EndPoint.Port); // Assert.Equal(100, server.Listeners[0].BackLog); // Assert.Equal(Listener.DefaultBackLog, server.Listeners[1].BackLog); }
static IServer CreateSocketServer <TPipelineFilter>(ServerOptions serverOptions) where TPipelineFilter : IPipelineFilter, new() { var server = new SuperSocketServer(); server.NetEventOnConnect = NetEventOnConnect; server.NetEventOnCloese = NetEventOnCloese; server.NetEventOnReceive = NetEventOnReceive; var services = new ServiceCollection(); services.AddLogging(); var pipelineFilterFactoryList = new List <IPipelineFilterFactory>(); pipelineFilterFactoryList.Add(new DefaultPipelineFilterFactory <TPipelineFilter>()); server.Configure(serverOptions, services, pipelineFilterFactoryList); Logger = SuperSocketServer.GetLogger(); return(server); }