public void Send(BaseTransportMessage message) { var data = _dataProvider.Serialize(message).ToString(); var dataBytes = data.GetBytes(); var prefixedDataBytes = ByteUtils.PrefixBufferSize(dataBytes); _clientSocket.SendAsync(new ArraySegment <byte>(prefixedDataBytes), SocketFlags.None); }
public override void Send <T>(ObjectId clientId, T data) { var tcpServer = TcpSocketServer; if (tcpServer == null) { throw new NullReferenceException($"Unable send data through {nameof(TypedServiceProvider)} because it is null."); } var dataJson = _dataProvider.Serialize(data).ToString(); tcpServer.Send(clientId, dataJson.GetBytes()); }
public void Send <T>(T message) where T : BaseTransportMessage { if (message.IsRemote) { return; } L.Log($"{WebSocketServerContext.LogServerName}: sending message..."); var data = _commonJsonDataProvider.Serialize(message); if (_clientsHandlers.TryGetValue(message.SessionId, out var client)) { // Sends message to client with specified SessionId. client.SendToCurrentClient(data.ToString()); } else { // If client is not found it means that target client is not connected vie WebSocket. // throw new InvalidOperationException($"Unable to send data to client {message.SessionId} because it's not registered on WebSocket server."); } }