Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » Multi ping check in same time


Multi ping check in same time

Reply
  #1 (permalink)  
Old 09-22-10, 05:02 AM
deadManN deadManN is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Multi ping check in same time

hello guys, i have app, should check ping with multi server and then say if they are offline or online, i just done it on one server, but in multi server it don't work, like i send 1 request and before first finish, i send second , and .....

so please help me.....

Language : C#
Reply With Quote
  #2 (permalink)  
Old 09-23-10, 08:50 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Quote:
Originally Posted by deadManN View Post
hello guys, i have app, should check ping with multi server and then say if they are offline or online, i just done it on one server, but in multi server it don't work, like i send 1 request and before first finish, i send second , and .....

so please help me.....

Language : C#
Can you post the code that you have so far here? Would make it easier to help you.

Pete
__________________
Reply With Quote
  #3 (permalink)  
Old 09-23-10, 12:19 PM
deadManN deadManN is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Reply With Quote
  #4 (permalink)  
Old 09-23-10, 02:35 PM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi,

You will have to use a handler for each ping request. Probably now you get an error saying a previous Asynch request hasn't finished yet. Here's a part of your code and how I would handle it.

Add a tag to each panel with the name of the server.

So a for each panel loop

Code:
int i = 0;
            foreach (Panel p in this.Controls)
            {
                p.Tag = serverName.GetValue(i);
                i++;
            }

Create pinghandler (you have one so you can modify that one as needed):
Code:
        private void p_PingCompleted(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
        {
            string server = (string)e.UserState;
            //server holds the name of the server and you can then find the right panel with that name as tag.
            //e.Reply.RoundtripTime.ToString() gives u pingtime if u want
            //e.Reply.Status.ToString() gives status in text

            if (e.Reply.Status == IPStatus.Success)
            {

                foreach (Panel panel in this.Controls)
                {
                    if (panel.Tag.ToString().ToLower() == server.ToLower())
                    {
                        //do your stuff ok
                        panel.BackColor = Color.FromArgb(128, 0, 256, 0);
                    }
                }
            }
            else
            {
                foreach (Panel panel in this.Controls)
                {
                    if (panel.Tag.ToString().ToLower() == server.ToLower())
                    {
                        //do your error stuff
                        panel.BackColor = Color.FromArgb(128, 128, 128, 128);
                    }
                }
            }

        }
And make a for each loop to loop through your servers and ping them:

Code:
foreach (var servername in serverName)
            {
                Ping p = new Ping();
                p.PingCompleted += p_PingCompleted;
                p.SendAsync(servername.ToString(), 1000, servername.ToString());
            }
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish

Last edited by Yeroon; 09-23-10 at 02:40 PM.
Reply With Quote
  #5 (permalink)  
Old 09-23-10, 04:24 PM
deadManN deadManN is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
cant understand the first part... and it ping all in same time ?!

cuz for example if a server has high latency it take several sec till app load fully .... and maybe people try to launche game on offline server before notice that ....
that's why i wanna send ping requests all at once ... BTW, if u expline first part ... since i don't use panel, i used an array .... i can't get panel and the tag ....
Reply With Quote
  #6 (permalink)  
Old 09-23-10, 09:28 PM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi I meant you use panels on your form where you color them. For the ping completed to know what panel to use, I use the tag of the panels to identify them. So the panels I mean are Panel1, Panel2 etc. I found them on the Form1.cs form. I assume that is the form that does the ping.

You fill an array of serverName (10 items max). And you have 10 panels.

Then add tag to Panel with:

Code:
            int i = 0; //counter for array of serverName
            foreach (Panel p in this.Controls) //loop through your 10 panels
            {
                p.Tag = serverName.GetValue(i); //set tag to serverName array entry with the number i
                i++; // go next i for next item in array
            }

The other ping completed code then has also the serverName for all the calls and you lookup[ the right panel and set the color to green (ok) or red (error).

And yes it does all the pings at the same time.

Code:
foreach (var servername in serverName) // loop through all servers
            {
                Ping p = new Ping(); // make new ping request
                p.PingCompleted += p_PingCompleted; // add handler
                p.SendAsync(servername.ToString(), 1000, servername.ToString()); //do asynch ping, so the loop keeps going because it is asynch. give max 1 second (1000ms) for a ping 
            }
I hope this clears it up
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #7 (permalink)  
Old 09-24-10, 02:32 AM
deadManN deadManN is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
this function don't work ....
and give me error.. i tried this in refresh function and formload handler...


int i = 0;
foreach (Panel p in this.Controls)
{
p.Tag = realmList.GetValue(i);
i++;
}

and one more question, the way these things work, if the person filled 3rd server realm, and put empty for 1st and second... what will happen? it gonna show ping of 3rd realm in 3rd panel, while in listBox it's on 1st slot ?!

and the way u said it check all at once... so my application wont hang for min? since i still couldn't test that due to error ... it say "Unable to cast object of type 'System.Windows.Forms.ProgressBar' to type 'System.Windows.Forms.Panel'."


///////////
edit:
one more thing... what if i gonna add other panel to my application ?! since once may i need new functionallity that need other panel

Last edited by deadManN; 09-24-10 at 02:44 AM.
Reply With Quote
  #8 (permalink)  
Old 09-24-10, 06:52 AM
deadManN deadManN is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
One more thing.. dunno why can't edit last post....

i see you use e server name to assign to ping class
but really serverName is teh name i show in listBox, but realmList is the IP or server Url .....
Reply With Quote
  #9 (permalink)  
Old 09-24-10, 01:48 PM
deadManN deadManN is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
hey, from morning i look taht when u come online, so u become on line after 15 h of checking
Reply With Quote
  #10 (permalink)  
Old 09-24-10, 01:52 PM
deadManN deadManN is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Man , have to go to bank with my father, his eyes are weak so ...
i'll be back by 10 min
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for Updates MikeFairbrother Visual Basic 0 09-16-06 10:27 AM
Super class seo services extreme90 General Advertisements 0 12-28-05 12:45 PM
How to change a dynamic object like time? LEN2884 C/C++ 0 05-27-05 04:55 AM
time adjustment dex002 PHP 2 05-09-05 12:50 PM
Showing time is users time zone? Nasimov PHP 1 11-20-03 07:14 AM


All times are GMT -5. The time now is 02:19 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.