LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2009, 05:44 AM   #1
wagmare
Member
 
Registered: Jan 2009
Posts: 62

Rep: Reputation: 15
unix socket programming


hi friends,
is there any way to find the recv() side socket descriptor that its peer is closed at the other side ..
server will keep sending and client will receives it ... if client process closed i can get errno :EPIPE
but if the server process closed .. recv() in client will receive just value '0' and return sucess ....

is there any other way to find the recv socket property to tell the user that peer process is closed on the other side ...

i try poll() checking POLLRDHUP but in vain ... is there any other way left to find ...

because i want to show the user that the peer process is closed at the other side in recv() on client.c

please help me ...
 
Old 06-10-2009, 06:26 AM   #2
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
It's a while ago that I did some socket programming, but if I remember correctly, I did the following:

I used a select (poll will also work I assume) to detect that there is a read event on a socket. If the number of bytes read is zero, the connection is closed.

Note: There is a dedicated programming section here at LQ where you're question might have fitted better. Just an idea for the next time that you have a programnming related question.
 
Old 06-10-2009, 07:03 AM   #3
wagmare
Member
 
Registered: Jan 2009
Posts: 62

Original Poster
Rep: Reputation: 15
first thanks for reply ..
yes but i need to differentiate how the connection is closed ...
if the network failed ..or the peer process died ...

i will use your select suggestion and report if succeed ...
 
Old 06-10-2009, 11:17 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
Quote:
if the network failed ..or the peer process died ...
If you use a select and the network died, I doubt that select will indicate that there is a read event on that socket. So that one will catch the situation where the peer process died.

Your description in the first post indicates that it's one-way communication (server sends, client receives).
I think that you need to add two-way comms so the client can, at regular intervals) send a message to the server to check if it's still there and the server needs to reply. No reply or send errors indicate a network problem.
 
Old 06-10-2009, 11:53 PM   #5
wagmare
Member
 
Registered: Jan 2009
Posts: 62

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Wim Sturkenboom View Post
If you use a select and the network died, I doubt that select will indicate that there is a read event on that socket. So that one will catch the situation where the peer process died.


I think that you need to add two-way comms so the client can, at regular intervals) send a message to the server to check if it's still there and the server needs to reply. No reply or send errors indicate a network problem.
i solved the network problem with ioctl call of the device ... but only the peer process i not yet resolved ... i will try this select read call .. thanks for reply ...
 
  


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
problem in unix socket programming wagmare Linux - Networking 0 06-05-2009 05:53 AM
Is it anyway we can use C Socket programming (In unix) in Windows? haxpor Programming 3 07-24-2007 05:01 AM
PHP UNIX Domain Socket Programming anamericanjoe Programming 2 12-08-2006 02:10 AM
unix/socket programming, which book should i read first ??? b0nd Linux - General 2 05-06-2006 12:47 AM
Unix socket programming - how to sent a file Scrag Programming 9 03-28-2004 09:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:37 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