Beispiel #1
0
        public void OnSocketMessage(MessageEventArgs data)
        {
            if (data.IsText || data.IsPing)
            {
                CloseSocket(1003, "Unexpected message format");
                return;
            }
            var bytes = data.RawData;

            if (bytes.Length > 512 || bytes.Length == 0)
            {
                CloseSocket(1003, "Unexpected message size");
                return;
            }
            else
            {
                if (protocol != null)
                {
                    protocol.OnSocketMessage(new Reader(bytes, 0));
                }
                else
                {
                    protocol = ProtocolStore.Decide(this, new Reader(bytes, 0));
                    if (protocol == null)
                    {
                        CloseSocket(1003, "Ambiguous protocol");
                        return;
                    }
                }
            }
        }
Beispiel #2
0
 public void OnSocketMessage(byte[] data)
 {
     if (data.Length > 512 || data.Length == 0)
     {
         CloseSocket(1003, "Unexpected message size");
         return;
     }
     else
     {
         if (protocol != null)
         {
             protocol.OnSocketMessage(new DataReader(data, 0));
         }
         else
         {
             protocol = ProtocolStore.Decide(this, new DataReader(data, 0));
             if (protocol == null)
             {
                 CloseSocket(1003, "Ambiguous protocol");
                 return;
             }
         }
     }
 }