Beispiel #1
0
        /// <summary>
        /// Uses HTTP Protocol and accepts HTTP connections with Horse MVC Architecture
        /// </summary>
        public static IHorseServer UseMvc(this IHorseServer server, HorseMvc mvc, HttpOptions options)
        {
            MvcConnectionHandler handler  = new MvcConnectionHandler(mvc, mvc.AppBuilder);
            HorseHttpProtocol    protocol = new HorseHttpProtocol(server, handler, options);

            server.UseProtocol(protocol);
            return(server);
        }
Beispiel #2
0
        /// <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);
        }