Exemplo n.º 1
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            startingArg arg    = (startingArg)e.Argument;
            pingClient  client = new pingClient(arg.IP, arg.port);
            pingstats   report = new pingstats();

            report.pingsSent = 0;
            report.pingsLost = 0;
            report.pingTime  = 0;
            if (!client.connect())
            {
                while (true)
                {
                    if ((worker.CancellationPending == true))
                    {
                        e.Cancel = true;
                        break;
                    }
                    else
                    {
                        int ret = client.ping();
                        report.pingsSent += 1;
                        if (ret < 0)
                        {
                            report.pingsLost += 1;
                        }
                        //todo:try new connection
                        else
                        {
                            report.pingTime = ret;
                        }
                        worker.ReportProgress(0, report);
                        report.pingsSent = 0;
                        report.pingsLost = 0;
                        report.pingTime  = 0;
                        if (ret > 0 && ret < 60000 / arg.pingPerMin)
                        {
                            Thread.Sleep(60000 / arg.pingPerMin - ret);
                        }
                        if (ret <= 0)
                        {
                            Thread.Sleep(60000 / arg.pingPerMin);
                        }
                    }
                }
                client.end();
            }
            else
            {
                report.pingsSent = 1;
                report.pingsLost = 1;
                worker.ReportProgress(1, report);
            }
        }
Exemplo n.º 2
0
        private void buttonexitserver_Click(object sender, EventArgs e)
        {
            arguments.pingPerMin = Int32.Parse(textBoxPpm.Text);
            arguments.IP         = textBoxServerip.Text;
            arguments.port       = Int32.Parse(textBoxServerport.Text);
            startingArg arg    = arguments;
            pingClient  client = new pingClient(arg.IP, arg.port);

            if (!client.connect())
            {
                client.endServer();
            }
        }
Exemplo n.º 3
0
 private void buttonexitserver_Click(object sender, EventArgs e)
 {
     arguments.pingPerMin = Int32.Parse(textBoxPpm.Text);
     arguments.IP = textBoxServerip.Text;
     arguments.port = Int32.Parse(textBoxServerport.Text);
     startingArg arg = arguments;
     pingClient client = new pingClient(arg.IP, arg.port);
     if (!client.connect())
     {
         client.endServer();
     }
 }
Exemplo n.º 4
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            startingArg arg = (startingArg)e.Argument;
            pingClient client = new pingClient(arg.IP, arg.port);
            pingstats report = new pingstats();
            report.pingsSent = 0;
            report.pingsLost = 0;
            report.pingTime = 0;
            if (!client.connect())
            {
                while (true)
                {
                    if ((worker.CancellationPending == true))
                    {
                        e.Cancel = true;
                        break;
                    }
                    else
                    {
                        int ret = client.ping();
                        report.pingsSent += 1;
                        if (ret < 0)
                            report.pingsLost += 1;
                        //todo:try new connection
                        else
                            report.pingTime = ret;
                        worker.ReportProgress(0, report);
                        report.pingsSent = 0;
                        report.pingsLost = 0;
                        report.pingTime = 0;
                        if (ret > 0 && ret < 60000 / arg.pingPerMin)
                        {
                            Thread.Sleep(60000 / arg.pingPerMin - ret);
                        }
                        if (ret <= 0)
                            Thread.Sleep(60000 / arg.pingPerMin);
                    }
                }
                client.end();
            }
            else
            {
                report.pingsSent = 1;
                report.pingsLost = 1;
                worker.ReportProgress(1, report);
            }
        }