private bool Send() { byte[] data; if (SLClient == null || DBSend == null || !SLClient.Connected || DBSend.IsAllRead || !DBSend.Read(out data)) { return(false); } byte[] result_data = TcpAsyncCommon.CreatePacket(data, PacketMode);// result.ToArray(); if (result_data.IsNullOrEmpty()) { return(false); } int sent = 0; int size = result_data.Length; SendTimeout.Reset(); do { int packet = size - sent; if (packet > TcpAsyncServer.PacketSizeTCP) { packet = TcpAsyncServer.PacketSizeTCP; } try { sent += SLClient.Send(result_data, sent, packet, SocketFlags.None); //Thread.Sleep(1); } catch (Exception ex) { Exceptions.Write(ex); this.StopClient(); return(false); } if (SendTimeout.IsTriggered) { return(false); } }while (sent < size); return(true); }
private bool SendThread(string key) { if (D3BSend == null || key.IsNullOrEmpty()) { return(false); } BufferedArray <byte[]> DBuffer = D3BSend.Get(key); if (DBuffer == null || DBuffer.IsAllRead) { return(false); } StateObject state = this.GetState(key); Socket handler = this.GetHandler(key); byte[] data; if (!handler.IsConnected() || DBuffer == null || DBuffer.IsAllRead || !DBuffer.Read(out data)) { return(false); } byte[] result_data = TcpAsyncCommon.CreatePacket(data, PacketMode); if (data.IsNullOrEmpty()) { return(false); } int sent = 0; int size = result_data.Length; do { int packet = size - sent; if (packet > PacketSizeTCP) { packet = PacketSizeTCP; } try { while (Speed > MaxSpeed) { Thread.Sleep(1); } int bytes_send = handler.Send(result_data, sent, packet, SocketFlags.None); sent += bytes_send; if (bytes_send > 0) { BandwidthBuffer.Write((int)((double)40 * Math.Ceiling((double)bytes_send / 1500)) + bytes_send); } } catch (Exception ex) { Exceptions.Write(ex); return(false); } }while (sent < size); return(true); }