/// <summary> /// 发送消息函数 /// </summary> public override void ProcessSendPacket() { if (mSendQueue == null) { return; } while (mSendQueue.Count > 0) { if (!IsConnect()) { continue; } // 当前待发送消息包 try { PBPacket packet = mSendQueue.Dequeue(); byte[] buffer = packet.Encoder(); mSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, (IAsyncResult async) => { try { int sendLen = mSocket.EndSend(async); } catch (Exception ex) { new Exception("not achieve " + ex.ToString()); } }, null); } catch (Exception ex) { new Exception("not achieve " + ex.ToString()); } } }
/// <summary> /// 处理发送消息包 /// </summary> public override void ProcessSendPacket() { if (mSendQueue == null) { return; } try { if (!IsConnect()) { return; } mCanSend = false; PBPacket packet = mSendQueue.Dequeue(); byte[] bytes = packet.Encoder(); // 发送消息 WebClient webClient = new WebClient(); webClient.UploadDataCompleted += ProcessReceiveThreadCallback; webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); webClient.UploadDataAsync(new Uri(mReqUrl), mHttpMethod, bytes); // LogUtils.Log("Http Send: " + JsonConvert.SerializeObject(msg), LType.Normal); } catch (Exception ex) { new Exception("not achieve " + ex.ToString()); } }