473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Checking is a networked computer is online before accessing a file

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
6 2670
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Mickel Grönroos | last post by:
Hi all, I have a silly question. Is there are simple way to check if the computer is connected to the Internet? It seems this should be a pretty straight-forward thing to do, but as I am totally...
3
by: ozarks | last post by:
I want to setup a database symbolic link within Windows XP to a network drive which has significanlty more space available and can't seem to get it working. Here is my setup.... - I am running...
2
by: caradhras | last post by:
I've been troubleshooting for a friend's charity. She wants their database accessible from both their PCs (I'll call them A & B), which are on a local network, both running A2K on Windows 98. I...
0
by: martin | last post by:
Hi, On my development machine I have vs.net installed and I am able to create a web application project No problem, this is located at http://localhost which I am guessing is the default. we...
5
by: Neil | last post by:
I am aiming to creat an ASP.NET webpage that will communicate with a database on the users computer. the user will go to my site, select his db from his computer and my webapge will run an algorithm...
2
by: Rishi Dhupar | last post by:
I am trying to upload a file to a networked device. All the users who have access to this page have access to the networked drive. Is there anyway of doing pretty much a copy file from local...
2
by: Vincent | last post by:
I have been trying to find some API routines that will allow me to determine the name of the computer that is accessing a file on a server. I have found the NetFileEnum call (returns the names of...
5
by: Lilith | last post by:
Would I be correct in assuming that the system file watcher is only valid for local drives and won't work for networked file system? -- Lilith
7
by: jdrott1 | last post by:
can this code be modified to run a .exe on a networked computer? i have this for starting a local program: System.Diagnostics.Process.Start("C:\program.exe") i.e. does it work with ip...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.