LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2005, 10:31 AM   #1
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Rep: Reputation: 30
can i connect to the network?


hi

i develop a program (c language) with linux.
every x second, i send some data to a server...
if the connection to the server fail, i would like to save to the local machine...

my solution:

i do a nfs link, /opt/good exist only on the server
my code:
Code:
exist = stat ( "/opt/good",&buf );
if(exist==0)
  printf("network on\n");
else
  printf("network off\n");

surely if the connection to the network fail, the program can stop...

what is the best way to do that?

thanks

Last edited by os2; 02-09-2005 at 10:33 AM.
 
Old 02-09-2005, 10:46 AM   #2
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 512

Rep: Reputation: 30
why dont you have the program "ping" the nfs?
 
Old 02-09-2005, 11:13 AM   #3
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Original Poster
Rep: Reputation: 30
that can work... but it's surely not the better solution

i can't imagine that: konqueror, kopete, icq, msn client... do a ping to know if they are a network problem...

what is the best solution?

Last edited by os2; 02-09-2005 at 11:25 AM.
 
Old 02-10-2005, 12:17 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you use TCP, you should get an error returned if the remote server does not respond/ack your pkts.
 
Old 02-10-2005, 12:59 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Re: can i connect to the network?

Quote:
Originally posted by os2
every x second, i send some data to a server...
What exactly are you doing there?
Writing bytes to a socket, fprint to an nfs share?


Cheers,
Tink
 
Old 02-10-2005, 01:23 AM   #6
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 512

Rep: Reputation: 30
wouldnt it return a standard error if it didnt get written? therefore you just need to look for the std error. if you are writing that frequently then a: does it matter if it misses the odd write? and b: (as an after thought) save the unwritten bits to a file and try to resend after connection (i.e. you dont get error anymore) has been re-estabilished.
 
Old 02-10-2005, 08:40 AM   #7
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Original Poster
Rep: Reputation: 30
Re: Re: can i connect to the network?

Quote:
Originally posted by Tinkster
What exactly are you doing there?
Writing bytes to a socket, fprint to an nfs share?


Cheers,
Tink

ya, i do fprintf to an nfs share
 
Old 02-10-2005, 11:38 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
That's a (if the network connection isn't too stable) rather
unreliable method, then, either way your program will
have at least the wait of the NFS timeout (3 minutes on
my machines) before it returns its -1 or the write fails ...

I'd go with the ping method....



Cheers,
Tink
 
Old 02-11-2005, 01:05 AM   #9
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 512

Rep: Reputation: 30
me too.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux machine does not connect to the network in windows network Bzuco Linux - Networking 2 07-19-2004 04:44 AM
How do I connect to my network? Nasdaq Linux - Networking 3 09-27-2003 05:31 AM
Connect to the network instinct311 Linux - Networking 2 09-03-2003 07:33 PM
Connect to the Network yangh66 Linux - Networking 2 06-21-2001 07:17 AM
Can't connect to the network anandg Linux - General 8 12-04-2000 10:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration