private void WSClient_ReConnect(EndPoint remorePoint) { lock (wslock) { if ((m_wsQClient == null || !m_wsQClient.IsConnected)) { //m_wsQClient = new AsyncTcpSession(); //m_wsQClient.Connected += new EventHandler(WSClient__Opened); //m_wsQClient.Closed += new EventHandler(WSClient__Closed); //m_wsQClient.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(WSClient__Error); //m_wsQClient.DataReceived += new EventHandler<SuperSocket.ClientEngine.DataEventArgs>(WSClient_DataReceived); //m_wsQClient.ReceiveBufferSize = 1024 * 16; //m_wsQClient.Connect(ipp); _logger.LogInformation($"启动服务"); //模拟行情 while (true) { var heartbeatStr = "26 00 30 32 32 35 31 33 30 30 30 35 00 00 00 00 00 00 00 00 00 00 00 BF 40 B2 73 E9 66 16 00 00 00 00 00 00 00 00"; Console.WriteLine(heartbeatStr); var h = HexStringUtil.HexStringToByteArray(heartbeatStr); SendBufferToClient(h); System.Threading.Thread.Sleep(1000); } } } }
/// <summary> /// 连接错误 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WSClient__Error(object sender, ErrorEventArgs e) { _logger.LogError($"[wsClient_Error]:{ipp.Address} {ipp.Port} :{e.Exception.Message},errmsg:{e.Exception.Message}"); var heartbeatStr = "26 00 30 32 32 35 31 33 30 30 30 35 00 00 00 00 00 00 00 00 00 00 00 BF 40 B2 73 E9 66 16 00 00 00 00 00 00 00 00"; var h = HexStringUtil.HexStringToByteArray(heartbeatStr); SendBufferToClient(h); //给客户端发送心跳消息 Thread.Sleep(15 * 1000); //休眠10秒 WSClient_ReConnect(ipp); //准备重连 }