private void RunDataSend() { byte[] buffer; int buffSize = Convert.ToInt32(dataSize.Text) * 1024; byte[] data = new byte[buffSize]; int maxPacketSize = Convert.ToInt16(packetSizeMax.Text); int minPacketSize = Convert.ToInt16(packetSizeMin.Text); Logger.Info("Sending " + buffSize + " bytes in packets between sizes " + minPacketSize + " and " + maxPacketSize + " to destination"); DefaultTcpTransportConnection transportConnection = new DefaultTcpTransportConnection(_transportManager.TCPTransport.OpenConnection("fubar", 2), ListeningReader); int sent = 0; int count = 0; try { int sendSize; while (sent < buffSize) { if (buffSize - sent < minPacketSize) { sendSize = buffSize - sent; } else { sendSize = rand.Next(minPacketSize, ((buffSize - sent) > maxPacketSize ? maxPacketSize : buffSize - sent) + 1); } buffer = new byte[sendSize]; rand.NextBytes(buffer); int startSend = Environment.TickCount; Logger.Info("Sending packet [" + count + "] of " + sendSize + "b"); transportConnection.SendDataToTransportSocket(buffer, buffer.Length); sent += sendSize; Logger.Info("Sent packet [" + count + "] of " + sendSize + "b, took " + (Environment.TickCount - startSend) + "ms, " + (buffSize - sent) + "b left."); Array.Copy(buffer, 0, data, sent - sendSize, sendSize); count++; int markerCount = sent / marker; int length = markerCount * marker; Invoke( new Action( () => { md5total.Text = markerCount.ToString() + "M"; md5sum.Text = Util.getSingleton().getMD5Hash(data, 0, length); outBytes.Text = sent.ToString(); PacketsOut.Text = count.ToString(); outKbps.Text = (sent / (Environment.TickCount - startTime) * 1000 / 1024).ToString(); })); } Logger.Debug("Completed send : " + sent); Invoke(new Action(() => { md5sum.Text = Util.getSingleton().getMD5Hash(data, 0, data.Length); md5total.Text = "All"; })); } catch (Exception e) { Logger.Error("Exception sending data : " + e.Message, e); } finally { transportConnection.Close(); } }
protected override TcpTransportConnection ProcessConnect(ITcpOverUdptSocket socket) { var connection = new DefaultTcpTransportConnection(socket, _form.ListeningReader); return connection; }
protected override TcpTransportConnection ProcessConnect(ITcpOverUdptSocket socket) { var connection = new DefaultTcpTransportConnection(socket, _form.ListeningReader); return(connection); }
private void RunDataSend() { byte[] buffer; int buffSize = Convert.ToInt32(dataSize.Text) * 1024; byte[] data = new byte[buffSize]; int maxPacketSize = Convert.ToInt16(packetSizeMax.Text); int minPacketSize = Convert.ToInt16(packetSizeMin.Text); Logger.Info("Sending " + buffSize + " bytes in packets between sizes " + minPacketSize + " and " + maxPacketSize + " to destination"); DefaultTcpTransportConnection transportConnection = new DefaultTcpTransportConnection(_transportManager.TCPTransport.OpenConnection("fubar", 2), ListeningReader); int sent = 0; int count = 0; try { int sendSize; while (sent < buffSize) { if (buffSize - sent < minPacketSize) { sendSize = buffSize - sent; } else { sendSize = rand.Next(minPacketSize, ((buffSize - sent) > maxPacketSize ? maxPacketSize : buffSize - sent) + 1); } buffer = new byte[sendSize]; rand.NextBytes(buffer); int startSend = Environment.TickCount; Logger.Info("Sending packet [" + count + "] of " + sendSize + "b"); transportConnection.SendDataToTransportSocket(buffer,buffer.Length); sent += sendSize; Logger.Info("Sent packet [" + count + "] of " + sendSize + "b, took " + (Environment.TickCount - startSend) + "ms, " + (buffSize - sent) + "b left."); Array.Copy(buffer, 0, data, sent - sendSize, sendSize); count++; int markerCount = sent / marker; int length = markerCount * marker; Invoke( new Action( () => { md5total.Text = markerCount.ToString() + "M"; md5sum.Text = Util.getSingleton().getMD5Hash(data, 0, length); outBytes.Text = sent.ToString(); PacketsOut.Text = count.ToString(); outKbps.Text = (sent / (Environment.TickCount - startTime) * 1000 / 1024).ToString(); })); } Logger.Debug("Completed send : " + sent); Invoke(new Action(() => { md5sum.Text = Util.getSingleton().getMD5Hash(data, 0, data.Length); md5total.Text = "All"; })); } catch (Exception e) { Logger.Error("Exception sending data : " + e.Message, e); } finally { transportConnection.Close(); } }