示例#1
0
        public void Send(int messageType, IRealTimeMessage message)
        {
            OnBeforeMessageSend(message);
            var messageData      = message.Serialize(MessageSerializer);
            var messageTypeBytes = BitConverter.GetBytes(messageType);

            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(messageTypeBytes);
            }

            using (var stream = new MemoryStream(messageData.Length + MessageTypeBytesLength))
            {
                stream.Write(messageTypeBytes, 0, MessageTypeBytesLength);
                stream.Write(messageData, 0, messageData.Length);
                var data = stream.GetBuffer();

                if (isOpened)
                {
                    connection.Send(data);
                }
            }
        }
示例#2
0
 public abstract void OnMessageReceive(IRealTimeMessage message);
示例#3
0
 public abstract void OnBeforeMessageSend(IRealTimeMessage message);
示例#4
0
 public async Task SendMessageAsync(RealtimeEventType eventType, IRealTimeMessage message)
 {
     await _hubContext.Clients.Clients(UserConnections)
     .SendCoreAsync(eventType.ToString(), new object[] { message });
 }