Esempio n. 1
0
        public static void DecodeMessage(Session session, WebMessage msg)
        {
            // do some complex decode actions here ...

            Byte[] bytes = msg.RawContent;
            if (bytes == null || bytes.Length <= 0) return; // nothing needs to decode

            if (msg.IsString())
            {
                Encoding encode = Encoding.UTF8;
                if (msg.MessageContent.Length == 0) msg.MessageContent = encode.GetString(bytes, 0, bytes.Length);
                else msg.MessageContent += encode.GetString(bytes, 0, bytes.Length);
            }
            else
            {
                msg.RawContent = bytes;
            }
        }
Esempio n. 2
0
        //public override int OnSend(Session session, object data)
        //{
        //    int result = base.OnSend(session, data);
        //    m_WebSocketServer.Logger.Info("On Send - " + data.ToString());
        //    return result;
        //}

        protected override void ProcessMessage(SessionContext ctx)
        {
            if (ctx == null)
            {
                return;
            }

            WebMessage msg = ctx.Data as WebMessage;

            if (msg == null || !msg.IsString())
            {
                ctx.Session.Close();
                return;
            }
            else
            {
                var reqctx = new RequestContext(new WebSocketSession(ctx.Session), msg.MessageContent, m_WebSocketServer.Flags);
                reqctx.RequestPath = WebMessage.GetSessionData(ctx.Session, "Path").ToString();
                reqctx.Headers     = new Dictionary <string, string>(msg.Headers);
                m_WebSocketServer.RequestHandler.HandleRequest(reqctx);
            }
        }