LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 09-24-2004, 11:03 AM   #1
sasha_baranov
LQ Newbie
 
Registered: Aug 2004
Location: New York
Posts: 6

Rep: Reputation: 0
How to determine lost socket connection


Hi, All.
I am a new Linux programmer.
I made a Linux TCP server for control applications. When some TCP client
connects to it, the program goes into infinite console loop, getting characters, echoing them to client, parsing commands etc. Everything is OK until the client unexpectedly terminates the connection. I have to detect this event inside the loop and break. I thought that it might be done by analyzing socket state (i.e. if the state is not ESTABLISHED - break the loop) but from various examples and HOWTOs I did not see how to do it. It seems that I have to solve this problem in different way.
Can anybody criticize and prompt?
 
Old 09-24-2004, 04:46 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,569

Rep: Reputation: 171Reputation: 171
You probably get 'Broken pipe', right? If so, you should block SIGPIPE signal (set it's handler to SIG_IGN). Then, if you try to read/write from the closed socket you'll get EPIPE in errno (function result will be -1).
 
Old 09-24-2004, 04:58 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,569

Rep: Reputation: 171Reputation: 171
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php

There's a discussion going in Programming, so I'm closing this thread.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Socket Connection Failed: 111 Connection Refused degraffenried13 Linux - General 3 05-31-2009 01:17 AM
Socket connection refused problem James_dean Linux - Networking 1 09-23-2005 04:51 PM
Killing an socket connection czelaya Linux - Networking 0 04-18-2005 04:56 PM
How to detect lost socket connection sasha_baranov Programming 4 02-16-2005 11:46 PM
socket connection raven Programming 1 02-04-2002 11:53 AM


All times are GMT -5. The time now is 07:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration