public void Start(int port) { HorseServer server = new HorseServer(ServerOptions.CreateDefault()); server.UseWebSockets(async delegate { await Task.CompletedTask; }); server.Start(port); }
public AbsoluteConnectorTest() { _server = new HorseServer(ServerOptions.CreateDefault()); _server.UseWebSockets(async(socket) => { await socket.SendAsync("Welcome"); }, async(socket, message) => { _receivedMessages++; await Task.CompletedTask; }); }
static void Main(string[] args) { IServiceCollection services = new ServiceCollection(); HorseServer server = new HorseServer(); server.AddWebSockets(cfg => cfg.AddBus(services) //.UsePipeModelProvider(new NewtonsoftJsonModelSerializer()) .UsePayloadModelProvider(new SystemJsonModelSerializer()) .AddSingletonHandlers(typeof(Program)) /* * .OnClientConnected((info, data) => * { * WsServerSocket socket = new YourDerivedCustomSocket(info, data); * Task.FromResult(socket); * }) */ .OnClientReady(client => { Console.WriteLine("Client connected"); return(Task.CompletedTask); }) .OnClientDisconnected(client => { Console.WriteLine("Client disconnected"); return(Task.CompletedTask); }) .OnError(exception => Console.WriteLine("Error: " + exception))); server.UseWebSockets(services.BuildServiceProvider()); server.UseHttp((request, response) => { if (request.Path.Equals("/status", StringComparison.InvariantCultureIgnoreCase)) { response.SetToText(); response.StatusCode = HttpStatusCode.OK; response.Write("OK"); } else { response.StatusCode = HttpStatusCode.NotFound; } return(Task.CompletedTask); }); server.Run(26111); }
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"); } }