LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-13-2006, 07:38 PM   #1
compext
LQ Newbie
 
Registered: Dec 2006
Posts: 2

Rep: Reputation: 0
How to recognize that the server is currently unavailable?


I wrote 2 simple codes between a client and a server (run as daemon), the TCP connection is established seen from netstat. However, when the server is rebooted, the client is still pending in the "recv" function (it should return a value<=0, right?). While it is OK to kill the server with "killall". Is there any flags or options? Thanks.

Last edited by compext; 12-13-2006 at 07:45 PM.
 
Old 12-13-2006, 08:29 PM   #2
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
Welcome to LQ!

Try looking at the "select" function. This will return when one of multiple events occur, such as the socket being readable or writable, the connection is terminated at the other end, etc.

--Ian
 
Old 12-13-2006, 08:59 PM   #3
compext
LQ Newbie
 
Registered: Dec 2006
Posts: 2

Original Poster
Rep: Reputation: 0
I'm using a blocking socket, so the select function may not affect the "recv" function.
 
Old 12-14-2006, 11:50 PM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
While ago that I programmed sockets. Your client will not get any 'messages' if you don't stop the server application in a proper way. So when the server app is killed, it must close sockets etc.

Select and blocking sockets go very well together.
Code:
while(1)
{
  setup select
  call select (wait till something happens)
  if socket can be read, 
    read from socket
}
 
  


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
unable to print file: server-error-service-unavailable mashed Linux - Newbie 2 10-22-2006 06:04 PM
Apache Server Unavailable Outside Local PC's Eric_T Linux - Networking 20 07-24-2006 04:20 PM
server-error-service-unavailable lpr printing TheBrick Linux - General 1 07-11-2006 07:04 AM
lp:unable to print file:server-error-service-unavailable mitchloft Fedora 3 03-29-2005 12:26 PM
nfs server reported service unavailable: Address already in use Gargomel7 Linux - Networking 0 09-16-2003 11:10 AM

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

All times are GMT -5. The time now is 05:27 PM.

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