Пример #1
0
        private void SendFailure(SocketChannel channel, Exception ex)
        {
            //Logger.WriteDebug("this, Pipeline => MessageFailure");

            var pos   = ex.Message.IndexOfAny(new[] { '\r', '\n' });
            var descr = pos == -1 ? ex.Message : ex.Message.Substring(0, pos);

            byte[] response = Encoding.UTF8.GetBytes("HTTP/1.1 400 OK\r\n" +
                                                     "Content-Type: text/html; charset=UTF-8\r\n\r\n" +
                                                     "<doctype !html><html><head><title></title></head>" +
                                                     "<body>" + descr + "</body></html>\r\n");

            channel.Send(response);
            channel.Close();
        }
Пример #2
0
        private void SendChannel(SocketChannel channel, object message)
        {
            //Logger.WriteDebug(this, "Pipeline => SendChannel");

            try
            {
                Stream sendMessage = _encoder.Prepare(message);
                if (sendMessage.Length > 0)
                {
                    SendCompleted(channel.Send(sendMessage));
                }
            }
            catch (Exception ex)
            {
                SendFailure(channel, ex);
            }
        }