public bool SendMessage(WebSocketMessage message) { switch (State) { case WebChannelState.Closed: case WebChannelState.InitFailed: return false; case WebChannelState.Initializing: toSend.AddLast(message); return true; case WebChannelState.Open: // TODO encode and send byte[] encoded = EncodeMessage(message); return messageSource.SendMessage(encoded); default: return false; } }
public bool SendMessage(HttpMessage message) { if (message == null) { throw new ArgumentNullException("message"); } string header = message.Header.ToString(); byte[] bHeader = Encoding.UTF8.GetBytes(header); if (source.SendMessage(bHeader)) { byte[] content = message.Content; if (content.Length > 0) { return(source.SendMessage(content)); } return(true); } return(false); //byte[] buffer = Encoding.UTF8.GetBytes(message); //source.SendMessage(buffer, 0, buffer.Length); }