/// <summary>异步发出请求,并接收响应</summary> /// <param name="url">地址</param> /// <param name="data">POST数据</param> /// <returns></returns> public async Task <Byte[]> SendAsync(String url, Byte[] data) { var client = _Pool.Get(); try { // 发出请求 var rs = await SendAsync(url, data, client); if (rs == null || rs.Count == 0) { return(null); } return(rs.ToArray()); } finally { _Pool.Put(client); } }
/// <summary>打开客户端</summary> public virtual Boolean Open() { if (Active) { return(true); } lock (Root) { if (Active) { return(true); } var ss = Servers; if (ss == null || ss.Count == 0) { throw new ArgumentNullException(nameof(Servers), "未指定服务端地址"); } if (Pool == null) { Pool = new MyPool { Host = this } } ; if (Encoder == null) { Encoder = new JsonEncoder(); } //if (Encoder == null) Encoder = new BinaryEncoder(); if (Handler == null) { Handler = new ApiHandler { Host = this } } ; if (StatInvoke == null) { StatInvoke = new PerfCounter(); } if (StatProcess == null) { StatProcess = new PerfCounter(); } if (StatSend == null) { StatSend = new PerfCounter(); } if (StatReceive == null) { StatReceive = new PerfCounter(); } Encoder.Log = EncoderLog; var ct = Pool.Get(); try { // 打开网络连接 if (!ct.Open()) { return(false); } } finally { Pool.Put(ct); } ShowService(); var ms = StatPeriod * 1000; if (ms > 0) { _Timer = new TimerX(DoWork, null, ms, ms) { Async = true } } ; return(Active = true); } }