/// <summary> /// Sends string websocket message /// </summary> private static async Task <bool> SendInternalAsync(IConnector <TwinoWebSocket, WebSocketMessage> connector, string message) { byte[] data = await _writer.Create(WebSocketMessage.FromString(message)); TwinoWebSocket client = connector.GetClient(); if (client != null && client.IsConnected) { return(await client.SendAsync(data)); } return(false); }
/// <summary> /// Creates new websocket message and writes the model /// </summary> public WebSocketMessage Write(object model) { Type type = model.GetType(); string code; if (_typeCodes.ContainsKey(type)) { code = _typeCodes[type]; } else { ModelTypeAttribute attr = type.GetCustomAttribute <ModelTypeAttribute>(); code = attr == null ? type.Name : attr.TypeCode; _typeCodes.Add(type, code); _codeTypes.Add(code, type); } string content = code + "|" + Serializer.Serialize(model); return(WebSocketMessage.FromString(content)); }
/// <summary> /// Sends string websocket message /// </summary> private static bool SendInternal(IConnector <TwinoWebSocket, WebSocketMessage> connector, string message) { byte[] data = _writer.Create(WebSocketMessage.FromString(message)).Result; return(connector.Send(data)); }