/// <summary>
        /// Uses HMQ Protocol and accepts TCP connections.
        /// </summary>
        public static IHorseServer UseHmq(this IHorseServer server, IProtocolConnectionHandler <HorseServerSocket, HorseMessage> handler)
        {
            HorseMqProtocol protocol = new HorseMqProtocol(server, handler);

            server.UseProtocol(protocol);
            return(server);
        }
Exemple #2
0
        /// <summary>
        /// Uses TMQ Protocol and accepts TCP connections.
        /// </summary>
        public static ITwinoServer UseTmq(this ITwinoServer server, IProtocolConnectionHandler <TmqServerSocket, TmqMessage> handler)
        {
            TwinoTmqProtocol protocol = new TwinoTmqProtocol(server, handler);

            server.UseProtocol(protocol);
            return(server);
        }
Exemple #3
0
        /// <summary>
        /// Creates new Twino HTTP protocol handler
        /// </summary>
        public TwinoHttpProtocol(ITwinoServer server, IProtocolConnectionHandler <SocketBase, HttpMessage> handler, HttpOptions options)
        {
            Options  = options;
            _server  = server;
            _handler = handler;

            PredefinedHeaders.SERVER_TIME_CRLF = Encoding.UTF8.GetBytes("Date: " + DateTime.UtcNow.ToString("R") + "\r\n");
            _timeTimer = new Timer(s => PredefinedHeaders.SERVER_TIME_CRLF = Encoding.UTF8.GetBytes("Date: " + DateTime.UtcNow.ToString("R") + "\r\n"), "", 1000, 1000);
        }
Exemple #4
0
        /// <summary>
        /// Uses WebSocket Protocol and accepts HTTP connections which comes with "Upgrade: websocket" header data
        /// </summary>
        public static ITwinoServer UseWebSockets(this ITwinoServer server,
                                                 IProtocolConnectionHandler <WsServerSocket, WebSocketMessage> handler,
                                                 HttpOptions options)
        {
            //we need http protocol is added
            ITwinoProtocol http = server.FindProtocol("http");

            if (http == null)
            {
                TwinoHttpProtocol httpProtocol = new TwinoHttpProtocol(server, new WebSocketHttpHandler(), options);
                server.UseProtocol(httpProtocol);
            }

            TwinoWebSocketProtocol protocol = new TwinoWebSocketProtocol(server, handler);

            server.UseProtocol(protocol);
            return(server);
        }
Exemple #5
0
 public App(
     Routes routes,
     int port    = Constants.Port,
     string mode = Constants.ServerMode,
     IServerStatus serverStatus   = null,
     ISocketMachine socketMachine = null,
     IProtocolConnectionHandler protocolConnectionHandler = null,
     IMiniLogger logger = null
     )
 {
     Config                    = new ServerConfig(Constants.HostName, port, mode);
     Logger                    = logger ?? new MiniLogger(new LogConfig(Config.Mode));
     Status                    = serverStatus ?? new ServerStatus();
     SocketMachine             = socketMachine ?? new DotNetSocketMachine();
     ProtocolConnectionHandler = protocolConnectionHandler ?? new HttpConnectionHandler
     {
         SocketReader     = new InternalSocketReader(),
         DataParser       = new RequestParser(),
         RequestProcessor = new RouteHandler(routes)
     };
     SocketMachine.Configure(Config.Port, Config.HostName);
 }
Exemple #6
0
 /// <summary>
 /// Creates new HMQ Protocol handler
 /// </summary>
 public HorseMqProtocol(IHorseServer server, IProtocolConnectionHandler <HorseServerSocket, HorseMessage> handler)
 {
     _server  = server;
     _handler = handler;
 }
Exemple #7
0
 /// <summary>
 /// Creates new TMQ Protocol handler
 /// </summary>
 public TwinoTmqProtocol(ITwinoServer server, IProtocolConnectionHandler <TmqServerSocket, TmqMessage> handler)
 {
     _server  = server;
     _handler = handler;
 }
 /// <summary>
 /// Creates new Websocket protocol handler
 /// </summary>
 public TwinoWebSocketProtocol(ITwinoServer server, IProtocolConnectionHandler <WsServerSocket, WebSocketMessage> handler)
 {
     _server  = server;
     _handler = handler;
 }
Exemple #9
0
 /// <summary>
 /// Uses WebSocket Protocol and accepts HTTP connections which comes with "Upgrade: websocket" header data
 /// </summary>
 public static ITwinoServer UseWebSockets(this ITwinoServer server,
                                          IProtocolConnectionHandler <WsServerSocket,
                                                                      WebSocketMessage> handler)
 {
     return(UseWebSockets(server, handler, HttpOptions.CreateDefault()));
 }
 public HmqOverWsHandler(HorseMq server, IProtocolConnectionHandler <HorseServerSocket, HorseMessage> tmqProtocolHandler)
 {
     _server             = server;
     _tmqProtocolHandler = tmqProtocolHandler;
 }