private async Task DoEcho(Socket socket)
        {
            do
            {
                var clientSocket = await Task.Factory.FromAsync(
                    new Func <AsyncCallback, object, IAsyncResult>(socket.BeginAccept),
                    new Func <IAsyncResult, Socket>(socket.EndAccept),
                    null).ConfigureAwait(false);

                Console.WriteLine("ECHO SERVER :: CLIENT CONNECTED");

                var channel = new XmlChannel();
                channel.OnMessage(async m => {
                    var response = await _messageDispatcher.DispatchAsync(m).ConfigureAwait(false);
                    if (response != null)
                    {
                        try
                        {
                            await channel.SendAsync(response).ConfigureAwait(false);
                        } catch (Exception _e)
                        {
                            Console.WriteLine($"Oh NO!!! {_e}");
                        }
                    }
                });

                channel.Attach(clientSocket);

                while (true)
                {
                }
            } while(true);
        }
Beispiel #2
0
        private async Task DoEcho(Socket socket)
        {
            do
            {
                var clientSocket = await Task.Factory.FromAsync(
                    new Func <AsyncCallback, object, IAsyncResult>(socket.BeginAccept),
                    new Func <IAsyncResult, Socket>(socket.EndAccept),
                    null).ConfigureAwait(false);

                Console.WriteLine("ECHO SERVER :: CLIENT CONNECTED");

                var channel = new XmlChannel();
                //var channel = new JsonChannel();
                _messageDispatcher.Bind(channel);

                channel.Attach(clientSocket);

                while (true)
                {
                }
            } while (true);
        }