public void Run() { HorseMvc mvc = new HorseMvc(); HomeController cont = new HomeController(); Assert.NotNull(cont); mvc.Init(); Assembly asm = Assembly.GetExecutingAssembly(); mvc.CreateRoutes(asm); mvc.Use(); HorseServer server = new HorseServer(ServerOptions.CreateDefault()); server.UseMvc(mvc, HttpOptions.CreateDefault()); server.Start(47442); System.Threading.Thread.Sleep(1000); HttpClient client = new HttpClient(); HttpResponseMessage response = client.GetAsync("http://127.0.0.1:47442/home/get").Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public void Start(int port) { HorseServer server = new HorseServer(ServerOptions.CreateDefault()); server.UseWebSockets(async delegate { await Task.CompletedTask; }); server.Start(port); }
public int Start(int pingInterval = 3, int requestTimeout = 4) { Random rnd = new Random(); for (int i = 0; i < 50; i++) { try { int port = rnd.Next(5000, 65000); ServerOptions serverOptions = ServerOptions.CreateDefault(); serverOptions.Hosts[0].Port = port; serverOptions.PingInterval = pingInterval; serverOptions.RequestTimeout = requestTimeout; HorseServer server = new HorseServer(serverOptions); server.UseHorseMq(Server); server.Start(); Port = port; return(port); } catch { Thread.Sleep(2); } } return(0); }
/// <summary> /// Starts new server, connects to remote node clients and starts to listen incoming node connections /// </summary> public async Task Start() { foreach (HmqStickyConnector connector in Connectors) { connector.Run(); } if (_nodeServer != null && _nodeServer.IsRunning) { _nodeServer.Stop(); _nodeServer = null; await Task.Delay(500); } if (Server.Options.NodeHost == null) { return; } _nodeServer = new HorseServer(new ServerOptions { Hosts = new List <HostOptions> { Server.Options.NodeHost }, PingInterval = 15, RequestTimeout = 15 }); _nodeServer.Start(); }
public async Task Connect() { _server.Start(46431); await Task.Delay(1250); WsAbsoluteConnector connector = new WsAbsoluteConnector(TimeSpan.FromMilliseconds(500)); connector.AddHost("ws://127.0.0.1:46431"); connector.Run(); await Task.Delay(1250); Assert.True(connector.IsConnected); SocketBase client = connector.GetClient(); Assert.NotNull(client); Assert.True(client.IsConnected); }
static void StartServer() { HorseServer server = new HorseServer(ServerOptions.CreateDefault()); server.UseWebSockets(async(socket, data) => { Console.WriteLine("connected"); socket.Disconnected += c => Console.WriteLine("disconnected"); await Task.CompletedTask; }, async(socket, message) => { Console.Write(message); await socket.SendAsync(message); }); server.Options.PingInterval = 30; server.Start(); }
static void Main(string[] args) { ServerWsHandler handler = new ServerWsHandler(); HorseServer server = new HorseServer(new ServerOptions { PingInterval = 15, Hosts = new List <HostOptions> { new HostOptions { Port = 4083 } } }); server.UseWebSockets(handler); server.Start(); while (true) { Console.ReadLine(); Console.WriteLine(handler.Online + " Online"); } }