Esempio n. 1
0
        public void Start(int port)
        {
            TwinoServer server = new TwinoServer(ServerOptions.CreateDefault());

            server.UseWebSockets(async delegate { await Task.CompletedTask; });
            server.Start(port);
        }
Esempio n. 2
0
        /// <summary>
        /// Starts new server, connects to remote node clients and starts to listen incoming node connections
        /// </summary>
        public async Task Start()
        {
            foreach (TmqStickyConnector 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 TwinoServer(new ServerOptions
            {
                Hosts = new List <HostOptions> {
                    Server.Options.NodeHost
                },
                PingInterval   = 15,
                RequestTimeout = 15
            });

            _nodeServer.Start();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ServerWsHandler handler = new ServerWsHandler();
            TwinoServer     server  = new TwinoServer(new ServerOptions
            {
                PingInterval = 15,
                Hosts        = new List <HostOptions>
                {
                    new HostOptions
                    {
                        Port = 83
                    }
                }
            });

            server.UseWebSockets(handler);

            server.Start();

            while (true)
            {
                Console.ReadLine();
                Console.WriteLine(handler.Online + " Online");
            }
        }
Esempio n. 4
0
        static void StartServer()
        {
            ServerOptions serverOptions = ServerOptions.CreateDefault();

            serverOptions.Hosts[0].Port = 48050;

            ServerBuilder builder = new ServerBuilder();

            builder.LoadFromFile("options.json");

            builder.AddAuthenticator(new ClientAuthenticator());
            builder.AddAuthorization(new Authorization());
            builder.AddDefaultDeliveryHandler(new DeliveryHandler());
            builder.AddDefaultChannelHandler(new ChannelHandler());
            builder.AddDefaultChannelAuthenticator(new ChannelAuthenticator());

            TwinoServer twinoServer = new TwinoServer(serverOptions);

            MqServer server = builder.CreateServer();

            twinoServer.UseMqServer(server);
            twinoServer.Start();

            Console.WriteLine("Server started");
            _server = server;
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public void Connect()
        {
            _server.Start(46431);
            System.Threading.Thread.Sleep(250);

            WsAbsoluteConnector connector = new WsAbsoluteConnector(TimeSpan.FromSeconds(1));

            connector.AddHost("ws://127.0.0.1:46431");
            connector.Run();
            System.Threading.Thread.Sleep(1000);

            Assert.True(connector.IsConnected);

            SocketBase client = connector.GetClient();

            Assert.NotNull(client);
            Assert.True(client.IsConnected);
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            TwinoMvc    mvc    = new TwinoMvc();
            TwinoServer server = new TwinoServer();

            mvc.Init();
            server.UseMvc(mvc, HttpOptions.CreateDefault());
            server.Start();
            server.BlockWhileRunning();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            TwinoMvc    mvc    = new TwinoMvc();
            TwinoServer server = new TwinoServer();

            mvc.Init();
            server.UseMvc(mvc);
            server.Start(5000);
            server.BlockWhileRunning();
        }
Esempio n. 9
0
        public void Start(int pingInterval = 3, int requestTimeout = 4)
        {
            ServerOptions serverOptions = ServerOptions.CreateDefault();

            serverOptions.Hosts[0].Port  = Port;
            serverOptions.PingInterval   = pingInterval;
            serverOptions.RequestTimeout = requestTimeout;

            TwinoServer server = new TwinoServer(serverOptions);

            server.UseMqServer(Server);
            server.Start();
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            TwinoServer _server = new TwinoServer();

            _server = new TwinoServer(ServerOptions.CreateDefault());
            _server.UseWebSockets(async(socket) => { await socket.SendAsync("Welcome"); },
                                  async(socket, message) =>
            {
                Console.WriteLine("# " + message);
                await socket.SendAsync(message);
            });
            _server.Start(46100);
            _server.BlockWhileRunning();
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            using TwinoMvc mvc = new TwinoMvc();

            mvc.IsDevelopment = false;
            mvc.Init(twino =>
            {
                twino.Services.AddScoped <IScopedService, ScopedService>();
                twino.Services.AddTransient <IFirstService, FirstService>();
                twino.Services.AddTransient <ISecondService, SecondService>();

                twino.AddJwt(options =>
                {
                    options.Key              = "Very_very_secret_key";
                    options.Issuer           = "localhost";
                    options.Audience         = "localhost";
                    options.Lifetime         = TimeSpan.FromHours(1);
                    options.ValidateAudience = false;
                    options.ValidateIssuer   = false;
                    options.ValidateLifetime = true;
                });

                twino.Policies.Add(Policy.RequireRole("Admin", "Admin"));
                twino.Policies.Add(Policy.RequireClaims("IT", "Database", "Cloud", "Source"));
                twino.Policies.Add(Policy.Custom("Custom", (d, c) => true));
                twino.Services.AddHttpClient();

                twino.StatusCodeResults.Add(HttpStatusCode.Unauthorized, new JsonResult(new { Message = "Access denied" }));
            });

            CorsMiddleware cors = new CorsMiddleware();

            cors.AllowAll();

            mvc.Use(app =>
            {
                app.UseMiddleware(cors);
                app.UseMiddleware <TMid>();
                app.UseFiles("/download", "/home/mehmet/files");
            });

            TwinoServer server = new TwinoServer();
            var         opt    = HttpOptions.CreateDefault();

            opt.HttpConnectionTimeMax = 0;
            server.UseMvc(mvc, opt);
            server.Start(441);
            server.BlockWhileRunning();
        }
Esempio n. 12
0
        static void StartServer()
        {
            TwinoServer server = new TwinoServer(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();
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            TwinoServer server = new TwinoServer(ServerOptions.CreateDefault());

            server.UseTmq(async(socket, msg) =>
            {
                Console.WriteLine(msg);
                await Task.CompletedTask;
            });
            server.Start(82);

            TmqClient client = new TmqClient();

            client.Data.Properties.Add("Host", "localhost");
            client.ClientId = "123";

            client.Connect("tmq://localhost:82/sample");

            Console.ReadLine();
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            TwinoServer server = new TwinoServer(ServerOptions.CreateDefault());

            server.UseHttp(async(request, response) =>
            {
                if (request.Path.Equals("/plaintext", StringComparison.InvariantCultureIgnoreCase))
                {
                    response.SetToText();
                    await response.WriteAsync("Hello, World!");
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NotFound;
                }
            });

            server.Start(82);
            server.BlockWhileRunning();
        }
Esempio n. 15
0
        public void Run(params PackageReader[] readers)
        {
            ServerOptions options = ServerOptions.CreateDefault();

            options.Hosts.FirstOrDefault().Port = _port;

            Server = new TwinoServer(ServerOptions.CreateDefault());
            Server.UseWebSockets(async(socket, message) =>
            {
                string msg = message.ToString();

                foreach (PackageReader reader in readers)
                {
                    reader.Read(socket, msg);
                }

                await Task.CompletedTask;
            });

            Server.Start(_port);
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            TwinoServer server = new TwinoServer(ServerOptions.CreateDefault());

            server.UseHttp(async(request, response) =>
            {
                if (request.Path.Equals("/json", StringComparison.InvariantCultureIgnoreCase))
                {
                    response.SetToJson(new { message = "Hello, World!" });
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NotFound;
                }

                await Task.CompletedTask;
            }, HttpOptions.CreateDefault());

            server.Start();
            server.BlockWhileRunning();
        }
Esempio n. 17
0
        public void Run()
        {
            TwinoMvc mvc = new TwinoMvc();

            HomeController cont = new HomeController();

            Assert.NotNull(cont);

            mvc.Init();
            Assembly asm = Assembly.GetExecutingAssembly();

            mvc.CreateRoutes(asm);

            TwinoServer server = new TwinoServer(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);
        }