By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

Checking is a networked computer is online before accessing a file

P: n/a
I am trying to find a way to check if a computer on a network is
"online" so that I can access a file on a share.

In short I maintain a list of computers that have my service running
(in the client application) and in my client program I allow the user
to change the computer that they are accessing.

If a computer that is on the list becomes unplugged and I try to
access a file with a FileStream the filestream creation takes 8-10
seconds before timing out. I wanted to know if there was a way to
quickly (1-2 seconds) determine if the computer is online? Otherwise
is there a way to access the file and specify a timeout?

Thanks

Matt

Jun 7 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Ping it

That'll tell you if the pc is online or not.
If you get 'request timed out' then its offline, if you get an IP address
then its online.


<Ma*********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
>I am trying to find a way to check if a computer on a network is
"online" so that I can access a file on a share.

In short I maintain a list of computers that have my service running
(in the client application) and in my client program I allow the user
to change the computer that they are accessing.

If a computer that is on the list becomes unplugged and I try to
access a file with a FileStream the filestream creation takes 8-10
seconds before timing out. I wanted to know if there was a way to
quickly (1-2 seconds) determine if the computer is online? Otherwise
is there a way to access the file and specify a timeout?

Thanks

Matt

Jun 7 '07 #2

P: n/a
On 7 Jun, 16:27, MattPKai...@gmail.com wrote:
I am trying to find a way to check if a computer on a network is
"online" so that I can access a file on a share.

In short I maintain a list of computers that have my service running
(in the client application) and in my client program I allow the user
to change the computer that they are accessing.

If a computer that is on the list becomes unplugged and I try to
access a file with a FileStream the filestream creation takes 8-10
seconds before timing out. I wanted to know if there was a way to
quickly (1-2 seconds) determine if the computer is online? Otherwise
is there a way to access the file and specify a timeout?

Thanks

Matt
Hi Matt,

Take a look at the System.Net.NetworkInformation.Ping class.

HTH,
Gary
http://www.garyshort.org

Jun 7 '07 #3

P: n/a
System.Net.NetworkInformation.Ping I guess.

<Ma*********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
>I am trying to find a way to check if a computer on a network is
"online" so that I can access a file on a share.

In short I maintain a list of computers that have my service running
(in the client application) and in my client program I allow the user
to change the computer that they are accessing.

If a computer that is on the list becomes unplugged and I try to
access a file with a FileStream the filestream creation takes 8-10
seconds before timing out. I wanted to know if there was a way to
quickly (1-2 seconds) determine if the computer is online? Otherwise
is there a way to access the file and specify a timeout?

Thanks

Matt

Jun 7 '07 #4

P: n/a
yeah I forgot to mention that class.
<ga**@garyshort.orgwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
On 7 Jun, 16:27, MattPKai...@gmail.com wrote:
>I am trying to find a way to check if a computer on a network is
"online" so that I can access a file on a share.

In short I maintain a list of computers that have my service running
(in the client application) and in my client program I allow the user
to change the computer that they are accessing.

If a computer that is on the list becomes unplugged and I try to
access a file with a FileStream the filestream creation takes 8-10
seconds before timing out. I wanted to know if there was a way to
quickly (1-2 seconds) determine if the computer is online? Otherwise
is there a way to access the file and specify a timeout?

Thanks

Matt

Hi Matt,

Take a look at the System.Net.NetworkInformation.Ping class.

HTH,
Gary
http://www.garyshort.org

Jun 7 '07 #5

P: n/a
On Jun 7, 10:45 am, g...@garyshort.org wrote:
On 7 Jun, 16:27, MattPKai...@gmail.com wrote:
I am trying to find a way to check if a computer on a network is
"online" so that I can access a file on a share.
In short I maintain a list of computers that have my service running
(in the client application) and in my client program I allow the user
to change the computer that they are accessing.
If a computer that is on the list becomes unplugged and I try to
access a file with a FileStream the filestream creation takes 8-10
seconds before timing out. I wanted to know if there was a way to
quickly (1-2 seconds) determine if the computer is online? Otherwise
is there a way to access the file and specify a timeout?
Thanks
Matt

Hi Matt,

Take a look at the System.Net.NetworkInformation.Ping class.

HTH,
Garyhttp://www.garyshort.org
Gary,

Thanks a bunch. I didn't realize that a Ping class existed in .Net.
It must be new to .Net 2.0. Anyways this worked great.

Thanks Again,

Matt

Jun 7 '07 #6

P: n/a
On Thu, 07 Jun 2007 09:09:43 -0700, <Ma*********@gmail.comwrote:
Thanks a bunch. I didn't realize that a Ping class existed in .Net.
It must be new to .Net 2.0. Anyways this worked great.
Note that a computer (or other network device) may have blocking or
disabled ping responses. So this method is only reliable if you know for
sure that the target device does in fact respond to pings.

Also note that pinging will tell you the state of the computer at the
moment that you ping it. Immediately after you ping it, the computer
could drop off the network or otherwise become unreachable. So you still
need to be able to handle the case when you try to connect but cannot.

I'm not aware of a way to specify a timeout when creating a FileStream
instance, though there may be one. However, you can implement it yourself
by using a separate thread to create the instance, with a waitable event
to signal to you when it's done. You can wait on a waitable event with a
timeout, so that allows you to specify the timeout. The tricky part is if
the thread creating the instance eventually succeeds, but after your
timeout. You need a way to deal with cleaning up the FileStream instance
in that case, but that should be as simple as setting a flag that the
thread can check to see whether it needs to clean up the instance or not.

Which method to use depends on just how reliably you need your goal to
accomplished. If you *never* want the user to have to wait the 8-10
seconds that it could take when timing out, then you need to implement
your timeout yourself (or figure out how to change the timeout inherent in
creating a FileStream instance). If you're okay with it being quick most
of the time, with the occasional chance for still waiting the timeout,
then the "ping" method should be just fine.

Pete
Jun 7 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.