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); } } }
public abstract void OnMessageReceive(IRealTimeMessage message);
public abstract void OnBeforeMessageSend(IRealTimeMessage message);
public async Task SendMessageAsync(RealtimeEventType eventType, IRealTimeMessage message) { await _hubContext.Clients.Clients(UserConnections) .SendCoreAsync(eventType.ToString(), new object[] { message }); }