예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Server\n");

            //start server and bind to its local and remote API
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, wc) =>
            {
                //Connect action
                c.OnOpen += () => Task.Run((Action)connected);

                //Receive action
                c.OnReceive += async msg => {
                    await c.SendAsync("Hi!");
                    //Stampo su console
                    Console.WriteLine("Client message: \n" + msg);

                    //Rispondo con ack
                    await c.SendAsync("I've received the following message: " + msg);

                    //Chiudo connessione
                    //await c.CloseAsync();
                };

                //Disconnect action
                c.OnClose += (s, d) => Task.Run((Action)disconnected);
            });

            //Waiting for connection closing
            AppExit.WaitFor(cts, t);
        }
예제 #2
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Server\n");

            //start server and bind to its local and remote API
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, wc) =>
            {
                c.Bind <TaskAPI, IProgressAPI>(new TaskAPI());

                c.OnOpen  += () => Task.Run((Action)writeClientCount);
                c.OnClose += (s, d) => Task.Run((Action)writeClientCount);
            });

            Console.Write("{0} ", nameof(TestServer));
            AppExit.WaitFor(cts, t);
        }