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

            Console.WriteLine(command);
            Debug.WriteLine("NEW DATA: " + command);
        }
コード例 #2
0
 private void OnDataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     foreach (var @byte in e.Data)
     {
         _receiveBuffer.Add(@byte);
     }
 }
コード例 #3
0
 private void OnReceivedData(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     lock (socketLock)
     {
         socketResponse = Response.Parser.ParseFrom(e.Data);
         receivedEvent.Set();
     }
 }
コード例 #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);
 }
コード例 #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())));
        }
コード例 #6
0
        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);
        }
コード例 #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);
                }
            }
        }
コード例 #8
0
ファイル: Networking.cs プロジェクト: WolfCorps/TacControl
        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;
            }
        }
コード例 #9
0
ファイル: TWSCallback.cs プロジェクト: see0/SSAddin
 void DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     Logr.Log(String.Format("TWSCallback.DataReceived: {0}", e.Data));
 }
コード例 #10
0
 private void OnWebSocketBinary(object sender, DataReceivedEventArgs e)
     => OnBinaryMessage(e.Data);
コード例 #11
0
 protected void webSocketClient_DataReceived(object sender, DataReceivedEventArgs e)
 {
     m_CurrentMessage = Encoding.UTF8.GetString(e.Data);
     m_MessageReceiveEvent.Set();
 }
コード例 #12
0
ファイル: Socket.IO.cs プロジェクト: Paulalex85/Red-VS-Green
 void SocketDataReceivedFunction(object o, WebSocket4Net.DataReceivedEventArgs e)
 {
     Debug.WriteLine("Socket received data");
     Debug.WriteLine(e.Data.ToString());
 }
コード例 #13
0
 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);
 }
コード例 #14
0
 private void OnBinaryMessage(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     BinaryMessage(e.Data, 0, e.Data.Count()).GetAwaiter().GetResult();
 }
コード例 #15
0
 void Ws_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     DataReceived?.Invoke(this, e);
 }
コード例 #16
0
 static void btc_DataReceived(object sender, DataReceivedEventArgs e)
 {
     Console.WriteLine("data:"+e.Data.ToString());
 }
コード例 #17
0
ファイル: Form1.cs プロジェクト: jfarre20/Ubiquitous
 private void websocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     Debug.Print("Received data:" + e.Data);
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: sschoeb/TetherDrone
 private void WebSocketOnDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
 {
     string command = Encoding.ASCII.GetString(dataReceivedEventArgs.Data);
     Console.WriteLine(command);
     Debug.WriteLine("NEW DATA: " + command);
 }
コード例 #19
0
ファイル: Program.cs プロジェクト: afeng302/WebSocket4Net
        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();
        }
コード例 #20
0
		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);
		}
コード例 #21
0
 private void WebSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     Debug.WriteLine(e.Data);
 }
コード例 #22
0
ファイル: CQGCAdapter.cs プロジェクト: ralex1975/Polygon
        /// <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");
            }
        }
コード例 #23
0
 void webSocketClient_DataReceived(object sender, DataReceivedEventArgs e)
 {
     CurrentData = e.Data;
     DataReceiveEvent.Set();
 }
コード例 #24
0
ファイル: Form1.cs プロジェクト: zhaowumu/dzhyun
 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);
 }
コード例 #25
0
 private void WsClient_DataReceived(object sender, DataReceivedEventArgs e)
 {
     OnMessage(e.Data);
 }
コード例 #26
0
ファイル: Program.cs プロジェクト: Indifer/Test
 static void ws_DataReceived(object sender, DataReceivedEventArgs e)
 {
     ;
 }
コード例 #27
0
 protected virtual void OnTickersSocketDataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
 }
コード例 #28
0
ファイル: Program.cs プロジェクト: Jackie-Innover/3VR
 private static void WebSocket_DataReceived(object sender, DataReceivedEventArgs e)
 {
     _autoResetEvent.Set();
 }
コード例 #29
0
ファイル: MyClient.cs プロジェクト: hardhill/InfocenterWPF
 private void WebSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     OnDataRecieved?.Invoke(sender, e);
 }
コード例 #30
0
 void ws_DataReceived(object sender, DataReceivedEventArgs e)
 {
     var log = LogManager.GetLogger(Global.CallerName());
     log.Info("ws_DataReceived " + e.Data);
     this.OnData(e.Data);
 }
コード例 #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));
 }
コード例 #32
0
ファイル: NetHandler.cs プロジェクト: wsycarlos/ARIA
 void _socketInstance_DataReceived(object sender, DataReceivedEventArgs e)
 {
     _dispatcher.Receive(e.Data);
 }
コード例 #33
0
 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();
     }
 }
コード例 #34
0
 void _ReceiveData(object o, DataReceivedEventArgs args)
 {
 }
コード例 #35
0
 private void _client_DataReceived(object sender, DataReceivedEventArgs e)
 {
 }
コード例 #36
0
 private void onDataReceive(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     util.debugWriteLine("on data " + e.Data);
 }
コード例 #37
0
ファイル: WebSocketClient.cs プロジェクト: Jackie-Innover/3VR
        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;
            }
        }
コード例 #38
0
 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);
     }
 }
コード例 #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));
            }
        }
コード例 #40
0
ファイル: Program.cs プロジェクト: kiranreddy20/nestcam
 private static void Ws_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     ProcessReceivedData(e.Data);
 }
コード例 #41
0
ファイル: OBSRemote.cs プロジェクト: jfarre20/Ubiquitous
 void socket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
 }