Exemple #1
0
        private void WebSocketOnDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
        {
            string command = Encoding.ASCII.GetString(dataReceivedEventArgs.Data);

            Console.WriteLine(command);
            Debug.WriteLine("NEW DATA: " + command);
        }
 private void OnDataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     foreach (var @byte in e.Data)
     {
         _receiveBuffer.Add(@byte);
     }
 }
 private void OnReceivedData(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     lock (socketLock)
     {
         socketResponse = Response.Parser.ParseFrom(e.Data);
         receivedEvent.Set();
     }
 }
Exemple #4
0
 private void Data(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     Debug.Print("Got data: {0}", e.Data);
     if (m_Data == null)
     {
         return;
     }
     m_Data(this, e);
 }
Exemple #5
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void ReceivedMsg(object sender, WebSocket4Net.DataReceivedEventArgs args)
        {
            var msg       = args.Data;
            var codeArray = new byte[2] {
                msg[0], msg[1]
            };
            var code = (int)ProtobufHelper.GetCommand(codeArray);

            OnMessage?.Invoke(null, new MessageReceivedEventArgs(msg, (CommandType)Enum.Parse(typeof(CommandType), code.ToString())));
        }
        private void WebSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
        {
            ICommandResponse response;

            if (TryGetCommandResponse(e.Data, out response))
            {
                HandleResponse(response);
                return;
            }
            IEvent evnt;

            if (TryGetEvent(e.Data, out evnt))
            {
                HandleEvent(evnt);
                return;
            }
            throw new Exception("Don't know what to do with response: " + e.Data);
        }
Exemple #7
0
        private void OnSocketData(object sender, WebSocket4Net.DataReceivedEventArgs args)
        {
            WebSocket ws     = (WebSocket)sender;
            var       msgStr = GZipHelper.GZipDecompressString(args.Data);

            //System.Diagnostics.Trace.WriteLine($"{msgStr}");
            Huobi.WsResponseMessage wsMsg = JsonConvert.DeserializeObject <Huobi.WsResponseMessage>(msgStr);
            if (wsMsg.ping != 0)
            {
                ws.Send(JsonConvert.SerializeObject(new Huobi.WsPong()
                {
                    pong = wsMsg.ping
                }));
            }
            else if (wsMsg.pong != 0)
            {
                ws.Send(JsonConvert.SerializeObject(new Huobi.WsPing()
                {
                    ping = wsMsg.pong
                }));
            }
            else if (wsMsg.subbed != null)
            {
                // ignore;
                if (wsMsg.status != "ok")
                {
                    System.Diagnostics.Trace.WriteLine($"Failed to subscribe to {wsMsg.subbed}");
                }
                else
                {
                    System.Diagnostics.Trace.WriteLine($"Subscribed to {wsMsg.subbed}");
                }
            }
            else
            {
                var parts    = wsMsg.ch.Split('.');
                var response = JsonConvert.DeserializeObject <Huobi.WsTickResponseMessage>(msgStr);
                if (DetailTick != null)
                {
                    DetailTick.Invoke(parts[1], response.tick);
                }
            }
        }
Exemple #8
0
        private void OnBinaryMessage(object sender, DataReceivedEventArgs args)
        {
            var msg = args.Data;

            try
            {
                using (var stringReader = new MemoryStream(msg))
                    using (var reader = new Newtonsoft.Json.Cbor.CborDataReader(stringReader))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        var            parsedMsg  = serializer.Deserialize <JObject>(reader);
                        OnMessage(parsedMsg);
                    }
            }
            catch (Exception ex)
            {
                SentrySdk.CaptureException(ex);
                throw;
            }
        }
Exemple #9
0
 void DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     Logr.Log(String.Format("TWSCallback.DataReceived: {0}", e.Data));
 }
 private void OnWebSocketBinary(object sender, DataReceivedEventArgs e)
     => OnBinaryMessage(e.Data);
 protected void webSocketClient_DataReceived(object sender, DataReceivedEventArgs e)
 {
     m_CurrentMessage = Encoding.UTF8.GetString(e.Data);
     m_MessageReceiveEvent.Set();
 }
Exemple #12
0
 void SocketDataReceivedFunction(object o, WebSocket4Net.DataReceivedEventArgs e)
 {
     Debug.WriteLine("Socket received data");
     Debug.WriteLine(e.Data.ToString());
 }
 void ws_DataReceived(object sender, DataReceivedEventArgs e)
 {
     var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
     log.Info("ws_DataReceived " + e.Data);
     this.OnData(e.Data);
 }
 private void OnBinaryMessage(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     BinaryMessage(e.Data, 0, e.Data.Count()).GetAwaiter().GetResult();
 }
Exemple #15
0
 void Ws_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     DataReceived?.Invoke(this, e);
 }
 static void btc_DataReceived(object sender, DataReceivedEventArgs e)
 {
     Console.WriteLine("data:"+e.Data.ToString());
 }
Exemple #17
0
 private void websocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     Debug.Print("Received data:" + e.Data);
 }
Exemple #18
0
 private void WebSocketOnDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
 {
     string command = Encoding.ASCII.GetString(dataReceivedEventArgs.Data);
     Console.WriteLine(command);
     Debug.WriteLine("NEW DATA: " + command);
 }
Exemple #19
0
        static void wsClient_DataReceived(object sender, DataReceivedEventArgs e)
        {
            Console.WriteLine("wsClient_DataReceived. Length= [" + e.Data.Length + "]");

            Console.WriteLine("will close connect ...");
            Thread.Sleep(1000);

            ((WebSocket)sender).Close();
        }
		private void OnDataReceived(object sender, DataReceivedEventArgs e)
		{
			var args = new DataReceivedArgs();
			args.Data = new ArraySegment<byte>(e.Data, 0, e.Data.Length);
			Received.Invoke(this, args);
		}
Exemple #21
0
 private void WebSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     Debug.WriteLine(e.Data);
 }
Exemple #22
0
        /// <summary>
        ///     Socket connection data sending event handler. Called on response to requested or subscribed data.
        /// </summary>
        private void OnSocketData(object sender, DataReceivedEventArgs e)
        {
            try
            {
                using (locker.WriteLock())
                {
                    using (var stream = new MemoryStream(e.Data))
                    {
                        stream.Position = 0;
                        var msg = Serializer.Deserialize <ServerMsg>(stream);

                        //[ENABLE_CQGC_TRACE]WebApiTrace.InMessage(msg);

                        if (msg.logon_result != null)
                        {
                            Handle(msg.logon_result);
                        }
                        if (msg.logged_off != null)
                        {
                            Handle(msg.logged_off);
                        }
                        //if (msg.ping != null)
                        //    processPing(msg.ping);
                        //if (msg.pong != null)
                        //    processPong(msg.pong);
                        if (msg.information_report.Count > 0)
                        {
                            foreach (var info in msg.information_report)
                            {
                                Handle(info);
                            }
                        }
                        if (msg.market_data_subscription_status.Count > 0)
                        {
                            foreach (var subscriptionStatus in msg.market_data_subscription_status)
                            {
                                marketDataSubscriptionStatusReceivedEvent.Raise(subscriptionStatus);
                            }
                        }
                        if (msg.real_time_market_data.Count > 0)
                        {
                            foreach (var realTimeMarketData in msg.real_time_market_data)
                            {
                                realTimeMarketDataReceivedEvent.Raise(realTimeMarketData);
                            }
                        }
                        if (msg.trade_subscription_status.Count > 0)
                        {
                            foreach (var status in msg.trade_subscription_status)
                            {
                                tradeSubscriptionStatusReceivedEvent.Raise(status);
                            }
                        }
                        if (msg.trade_snapshot_completion.Count > 0)
                        {
                            foreach (var snapshot in msg.trade_snapshot_completion)
                            {
                                tradeSnapshotCompletionReceivedEvent.Raise(snapshot);
                            }
                        }
                        if (msg.order_status.Count > 0)
                        {
                            foreach (var orderStatus in msg.order_status)
                            {
                                if (orderStatus.contract_metadata != null)
                                {
                                    foreach (var metadata in orderStatus.contract_metadata)
                                    {
                                        contractMetadataReceivedEvent.Raise(metadata);
                                    }
                                }

                                orderStatusReceivedEvent.Raise(orderStatus);
                            }
                        }
                        if (msg.position_status.Count > 0)
                        {
                            foreach (var positionStatus in msg.position_status)
                            {
                                if (positionStatus.contract_metadata != null)
                                {
                                    contractMetadataReceivedEvent.Raise(positionStatus.contract_metadata);
                                }

                                positionStatusReceivedEvent.Raise(positionStatus);
                            }
                        }
                        if (msg.collateral_status.Count > 0)
                        {
                            foreach (var collateralStatus in msg.collateral_status)
                            {
                                collateralStatusReceivedEvent.Raise(collateralStatus);
                            }
                        }
                        if (msg.time_bar_report.Count > 0)
                        {
                            foreach (var report in msg.time_bar_report)
                            {
                                timeBarReportReceivedEvent.Raise(report.request_id, report);
                            }
                        }
                        //if (msg.time_and_sales_report.Count > 0)
                        //    foreach (TimeAndSalesReport report in msg.time_and_sales_report)
                        //       processTimeAndSalesReport(report);
                        if (msg.order_request_reject.Count > 0)
                        {
                            foreach (var message in msg.order_request_reject)
                            {
                                orderRequestRejectReceivedEvent.Raise(message.request_id, message);
                            }
                        }
                        if (msg.user_message.Count > 0)
                        {
                            foreach (var userMessage in msg.user_message)
                            {
                                userMessageReceivedEvent.Raise(userMessage);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error().Print(ex, "WS:OnSocketData failed to process an event");
            }
        }
 void webSocketClient_DataReceived(object sender, DataReceivedEventArgs e)
 {
     CurrentData = e.Data;
     DataReceiveEvent.Set();
 }
Exemple #24
0
 private void websocket_MessageReceived(object sender, DataReceivedEventArgs e)
 {
     strMessage = Encoding.UTF8.GetString(e.Data);
     objJson = JObject.Parse(strMessage);
     strRequestId = objJson.Value<string>("req_seq");
     strMessage = objJson.ToString();
     this.txtResponse.Invoke(new EventHandler(ShowMessage), e);
 }
 private void WsClient_DataReceived(object sender, DataReceivedEventArgs e)
 {
     OnMessage(e.Data);
 }
Exemple #26
0
 static void ws_DataReceived(object sender, DataReceivedEventArgs e)
 {
     ;
 }
 protected virtual void OnTickersSocketDataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
 }
Exemple #28
0
 private static void WebSocket_DataReceived(object sender, DataReceivedEventArgs e)
 {
     _autoResetEvent.Set();
 }
Exemple #29
0
 private void WebSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     OnDataRecieved?.Invoke(sender, e);
 }
 void ws_DataReceived(object sender, DataReceivedEventArgs e)
 {
     var log = LogManager.GetLogger(Global.CallerName());
     log.Info("ws_DataReceived " + e.Data);
     this.OnData(e.Data);
 }
Exemple #31
0
 /// <summary>
 /// Called when WebSocket data is received.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="DataReceivedEventArgs"/> instance containing the event data.</param>
 private void OnWebSocketDataReceived(object sender, W4N.DataReceivedEventArgs e)
 {
     Decode(new ArraySegment <byte>(e.Data));
 }
Exemple #32
0
 void _socketInstance_DataReceived(object sender, DataReceivedEventArgs e)
 {
     _dispatcher.Receive(e.Data);
 }
 private void OnDataReceivedCallback(object sender, DataReceivedEventArgs de)
 {
     if (de.Data.Length > 0)
     {
         mNetStream.PushInStream(de.Data);
     }
     else
     {
         LoggerSystem.Instance.Error("读取数据为0,将要断开此链接接:ws://" + mRemoteHost.ToString());
         DisConnect();
     }
 }
 void _ReceiveData(object o, DataReceivedEventArgs args)
 {
 }
 private void _client_DataReceived(object sender, DataReceivedEventArgs e)
 {
 }
Exemple #36
0
 private void onDataReceive(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     util.debugWriteLine("on data " + e.Data);
 }
Exemple #37
0
        private void websocket_DataReceived(object sender, DataReceivedEventArgs e)
        {
            var response = WebSocketBlockWrite.BytesToResponse(e.Data);

            if (response.ResponseType == WebSocketResponseType.PutFileResponse)
            {
                Interlocked.Increment(ref _getPutResponseCnt);
            }
            switch (response.ResponseType)
            {
                case WebSocketResponseType.AuthenticationResponse:
                    {
                        if (response.ExecuteSuccess)
                        {
                            Status = WebSessionStatus.Active;
                            Console.WriteLine("WebSocket Connection is opened" + Environment.NewLine);
                        }
                        else
                        {
                            Status = WebSessionStatus.Inactive;
                            Interlocked.Increment(ref _loginAttemps);
                            Console.WriteLine("Exception during authentication: ");
                        }
                        _waitConnectionOpenedEvent.Set();
                        break;
                    }
                case WebSocketResponseType.PutFileResponse:
                    {
                        //var putFileResponse = JsonConvert.DeserializeObject<PutFileResponse>(e.Message);
                        //WebSocketNotificationHandler.ReceiveResponse(requestId, putFileResponse.ExecuteSuccess);
                        WebSocketNotificationHandler.ReceiveResponse(response.RequestId, response.ExecuteSuccess);
                        break;
                    }
                default:
                    Console.WriteLine("Unrecognized WebSocket response");
                    break;
            }
        }
 private void socket_DataReceived(object sender, DataReceivedEventArgs e)
 {
     Console.WriteLine(e.Data.Length);
     if (e.Data.Length == 0)
     {
         if (SendResultHandler != null)
             SendResultHandler(Guid.Empty, false);
     }
     else if (e.Data.Length == 24)
     {
         Guid guid = e.Data.FromiTripByteArray(Encoding.UTF8);
         if (SendResultHandler != null)
             SendResultHandler(guid, true);
         Console.WriteLine(guid.ToString());
     }
     else
     {
         IPackage package = new ipp_Package(e.Data);
         if (ReceivedHandler != null)
             ReceivedHandler(package);
     }
 }
Exemple #39
0
        private void WhenDataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
        {
            if (Info.Status == "closed")
            {
                return;
            }

            IsReceiving       = true;
            Info.LastDataTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            string overloadFileName = "";

            lock (StreamDataFileName)
            {
                Info.Status = IsRecording ? "recording" : "receiving";

                if (!IsRecording || StreamDataFileName.Length <= 0)
                {
                    return;
                }

                m_CurrentRecordSize += e.Data.Length;
                if (m_CurrentRecordSize > MaxRecordSize)
                {
                    overloadFileName = String.Copy(StreamDataFileName);
                    CommonLog.Info("Exceeded max size limit of " + MaxRecordSize + " - " + overloadFileName);
                }
                else
                {
                    if (e.Data.Length > 4 &&
                        (e.Data[0] == 0 && e.Data[1] == 0 && e.Data[2] == 0 && e.Data[3] == 1) &&
                        m_RawVideoFilePath.Length > 0)
                    {
                        m_VideoCache.Write(e.Data, 0, e.Data.Length);
                        m_VideoCacheSize += e.Data.Length;

                        if (m_VideoCacheSize >= MaxCacheSize)
                        {
                            if (m_RawVideoFilePath.Length > 0 && File.Exists(m_RawVideoFilePath))
                            {
                                try
                                {
                                    using (var fs = new FileStream(m_RawVideoFilePath, FileMode.Append, FileAccess.Write))
                                    {
                                        var writer = new BinaryWriter(fs);
                                        writer.Write(m_VideoCache.ToArray());
                                        writer.Close();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    CommonLog.Error(ex.ToString());
                                }
                            }
                            else
                            {
                                CommonLog.Error("Video stream data file not found: " + m_RawVideoFilePath);
                            }

                            m_VideoCacheSize = 0;
                            if (m_VideoCache != null)
                            {
                                m_VideoCache.Dispose();
                            }
                            m_VideoCache = new MemoryStream();
                        }
                    }
                    else if (e.Data.Length > 0 && m_RawAudioFilePath.Length > 0)
                    {
                        m_AudioCache.Write(e.Data, 0, e.Data.Length);
                        m_AudioCacheSize += e.Data.Length;

                        if (m_AudioCacheSize >= MaxCacheSize)
                        {
                            if (m_RawAudioFilePath.Length > 0 && File.Exists(m_RawAudioFilePath))
                            {
                                try
                                {
                                    using (var fs = new FileStream(m_RawAudioFilePath, FileMode.Append, FileAccess.Write))
                                    {
                                        var writer = new BinaryWriter(fs);
                                        writer.Write(m_AudioCache.ToArray());
                                        writer.Close();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    CommonLog.Error(ex.ToString());
                                }
                            }
                            else
                            {
                                CommonLog.Error("Audio stream data file not found: " + m_RawAudioFilePath);
                            }

                            m_AudioCacheSize = 0;
                            if (m_AudioCache != null)
                            {
                                m_AudioCache.Dispose();
                            }
                            m_AudioCache = new MemoryStream();
                        }
                    }
                } // end if filesize ok
            }     // end of lock

            if (overloadFileName.Length > 0)
            {
                Task.Factory.StartNew(() => Export(overloadFileName));
            }
        }
Exemple #40
0
 private static void Ws_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     ProcessReceivedData(e.Data);
 }
Exemple #41
0
 void socket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
 }