Beispiel #1
0
        private void buttonChooseFile_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            FileName = saveFileDialog1.FileName;
            ParameterizedThreadStart pts = new ParameterizedThreadStart(ReceiverThread);
            Thread thread             = new Thread(pts);
            ReceiverThreadParam param = new ReceiverThreadParam();

            param.remoteIp   = IPAddress.Parse(textBoxRemoteIp.Text);
            param.remotePort = UInt16.Parse(textBoxRemotePort.Text);
            thread.Start(param);
        }
Beispiel #2
0
        void ReceiverThread(object obj)
        {
            ReceiverThreadParam param = (ReceiverThreadParam)obj;
            ulong iterations_counter  = 0;
            ulong ticks_sum           = 0;

            object[] args;

            BytesReceived = 0;
            BytesSent     = 0;

            while (!StopFlag)
            {
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                byte [] buff;

                Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                if (sock == null)
                {
                    return;
                }
                receiverPackLib.SetOnMsgReady4TxParam(sock);
                try
                {
                    sock.Connect(param.remoteIp, param.remotePort);
                    LogUtility.LogUtility.LogFile("Connected", LogUtility.LogLevels.LEVEL_LOG_HIGH);
                    buff    = new byte[1];
                    buff[0] = (checkBoxPackMode.Checked) ? (byte)1 : (byte)0;
                    sock.Send(buff);
                    LogUtility.LogUtility.LogFile("Sent " + Convert.ToString(buff.Length), LogUtility.LogLevels.LEVEL_LOG_HIGH);
                }
                catch (SocketException se)
                {
                    args    = new object[1];
                    args[0] = se.Message;
                    Invoke(updateStatus, args);
                    continue;
                }
                DateTime startTime = DateTime.Now;
                if (checkBoxPackMode.Checked)
                {
                    PackMode(sock);
                }
                else
                {
                    RawMode(sock);
                }
                DateTime finishTime = DateTime.Now;
                LogUtility.LogUtility.LogFile("Finished " + Convert.ToString(finishTime.Ticks - startTime.Ticks), ModuleLogLevel);
                args = new object[5];

                if (iterations_counter == 0)
                {
                    args[0]       = true;
                    args[1]       = (ulong)(finishTime.Ticks - startTime.Ticks);
                    args[3]       = (uint)BytesReceived;
                    args[4]       = (uint)BytesSent;
                    BytesReceived = 0;
                    BytesSent     = 0;
                }
                else
                {
                    args[0]    = false;
                    ticks_sum += (ulong)(finishTime.Ticks - startTime.Ticks);
                    args[1]    = ticks_sum / (iterations_counter + 1);
                    args[3]    = (uint)(BytesReceived / iterations_counter);
                    args[4]    = (uint)(BytesSent / iterations_counter);
                }
                args[2] = iterations_counter + 1;
                Invoke(updateControls, args);
                iterations_counter++;
                sock.Close();
                sock = null;
                buff = null;
                receiverPackLib.Reset();
            }
        }