public async Task SendMessage(WebSocketMessage msg) { string szMsg = msg.ToString(); var bMsg = Encoding.UTF8.GetBytes(szMsg); var compressedMsg = GZipHelper.Compress(bMsg); using (var cts = new CancellationTokenSource(ReadTimeout)) { await clientWebSocket.SendAsync(new ArraySegment <byte>(compressedMsg), WebSocketMessageType.Binary, true, cts.Token); } }
public void SendSettingsToServer(string settings) { ConfigControlLogic.Instance.Log("Отправка сообщения на сервер."); WebSocketMessage data = new WebSocketMessage(AppName, DeviceName, settings, AuthToken, SessionID); if (socket != null && socket.IsAlive) { socket.Send(data.ToString()); } else { ConfigControlLogic.Instance.Log("Отправка не возможна. Нет подключения с сервером по сокету."); } }
private static void ProcessMessage_(Session session, WebSocketMessage message) { if (message.FrameType == WebSocketFrameTypes.Text && message.PayloadAsString() == "{}") { return; } var uri = new Uri(session.fullUrl); var query = HttpUtility.ParseQueryString(uri.Query); var url = GetUrl_(session, message); var request = new StringBuilder(); request.AppendLine(message.ToString()); request.AppendLine($"IsFinalFrame: {message.IsFinalFrame}"); request.AppendLine($"clientProtocol: {query["clientProtocol"]}"); request.AppendLine($"connectionData: {query["connectionData"]}"); SendRequest_(url, request.ToString()); }
private static void ProcessEvent(WebSocketMessage msg) { if (msg is ClientLoginResponse) { ClientLoginResponse loginResp = (ClientLoginResponse)msg; if (loginResp.JsonWebToken != null) { JWTToken = loginResp.JsonWebToken; UUID = loginResp.UUID; UserId = loginResp.UserId; } ProcessJsonMessage <ClientLoginResponse>(loginResp); } else if (msg is ClientReject) { ProcessJsonMessage <ClientReject>((ClientReject)msg); } else if (msg is SubscriptionResponse) { ProcessJsonMessage <SubscriptionResponse>((SubscriptionResponse)msg); } else if (msg is AccountRecord) { ProcessJsonMessage <AccountRecord>((AccountRecord)msg); } else if (msg is DailySettlementPrice) { ProcessJsonMessage <DailySettlementPrice>((DailySettlementPrice)msg); } else if (msg is FirmRecord) { ProcessJsonMessage <FirmRecord>((FirmRecord)msg); } else if (msg is OfficialFixingPrice) { ProcessJsonMessage <OfficialFixingPrice>((OfficialFixingPrice)msg); } else if (msg is RefereceRateMsg) { ProcessJsonMessage <RefereceRateMsg>((RefereceRateMsg)msg); } else if (msg is SecurityMasterRecord) { ProcessJsonMessage <SecurityMasterRecord>((SecurityMasterRecord)msg); } else if (msg is UserRecord) { ProcessJsonMessage <UserRecord>((UserRecord)msg); } else if (msg is LastSale) { ProcessJsonMessage <LastSale>((LastSale)msg); } else if (msg is Quote) { ProcessJsonMessage <Quote>((Quote)msg); } else if (msg is CreditRecordUpdate) { ProcessJsonMessage <CreditRecordUpdate>((CreditRecordUpdate)msg); } else if (msg is DepthOfBook) { ProcessJsonMessage <DepthOfBook>((DepthOfBook)msg); } else if (msg is LegacyOrderAck) { ProcessJsonMessage <LegacyOrderAck>((LegacyOrderAck)msg); } else if (msg is LegacyOrderCancelRejAck) { ProcessJsonMessage <LegacyOrderCancelRejAck>((LegacyOrderCancelRejAck)msg); } else if (msg is ClientLogoutResponse) { ClientLogoutResponse logoutResp = (ClientLogoutResponse)msg; JWTToken = null; UserId = null; UUID = null; ProcessJsonMessage <ClientLogoutResponse>((ClientLogoutResponse)msg); } else if (msg is ClientHeartbeat) { ClientHeartbeat heartBeatReq = (ClientHeartbeat)msg; ProcessJsonMessage <ClientHeartbeat>((ClientHeartbeat)msg); ProcessHeartbeat(heartBeatReq.SeqNum); } else if (msg is UnknownMessage) { UnknownMessage unknownMsg = (UnknownMessage)msg; DoLog(string.Format("<<unknown {0}", unknownMsg.Resp)); } else if (msg is ErrorMessage) { ErrorMessage errorMsg = (ErrorMessage)msg; DoLog(string.Format("<<unknown {0}", errorMsg.Error)); } else { DoLog(string.Format("<<Unknown message type {0}", msg.ToString())); } Console.WriteLine(); }