示例#1
0
 /// <summary>
 /// 引发消息事件
 /// </summary>
 /// <param name="data"></param>
 /// <param name="opcode"></param>
 protected void OnMessage(byte[] data, WebSocketOpcode opcode)
 {
     if (this.Message != null)
     {
         var args = new WebSocketMessageEventArgs(opcode);
         args.Buffer = data;
         if (opcode == WebSocketOpcode.Text)
         {
             args.Message = this.encoding.GetString(data);
         }
         this.Message(this, args);
     }
 }
示例#2
0
        /// <summary>
        /// 触发一个消息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="opcode"></param>
        /// <param name="context"></param>
        internal protected void OnWebSocketNewMessage(HttpServerWebSocketContext context, byte[] data, WebSocketOpcode opcode)
        {
            var action = this.WebSocketNewMessage;

            if (action != null)
            {
                var e = new WebSocketMessageEventArgs(opcode);
                e.Buffer = data;
                if (opcode == WebSocketOpcode.Text)
                {
                    e.Message = this.Encoding.GetString(data);
                }
                action(context, e);
            }
        }