/// <summary> /// Uses WebSocket Protocol and accepts HTTP connections which comes with "Upgrade: websocket" header data /// </summary> public static IHorseServer UseWebSockets(this IHorseServer server, IProtocolConnectionHandler <WsServerSocket, WebSocketMessage> handler, HttpOptions options) { //we need http protocol is added IHorseProtocol http = server.FindProtocol("http"); if (http == null) { HorseHttpProtocol httpProtocol = new HorseHttpProtocol(server, new WebSocketHttpHandler(), options); server.UseProtocol(httpProtocol); } HorseWebSocketProtocol protocol = new HorseWebSocketProtocol(server, handler); server.UseProtocol(protocol); return(server); }
/// <summary> /// Uses websocket protocol /// </summary> public static IHorseServer AddWebSockets(this IHorseServer server, HttpOptions options, Action <WebSocketServerBuilder> cfg) { //we need http protocol is added IHorseProtocol http = server.FindProtocol("http"); if (http == null) { HorseHttpProtocol httpProtocol = new HorseHttpProtocol(server, new WebSocketHttpHandler(), options); server.UseProtocol(httpProtocol); } WebSocketServerBuilder builder = new WebSocketServerBuilder(); cfg(builder); ModelWsConnectionHandler handler = builder.Build(); HorseWebSocketProtocol protocol = new HorseWebSocketProtocol(server, handler); server.UseProtocol(protocol); return(server); }