UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2002-07-27 01:21 AM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: 8.1 - send() hangs up when sending to a turned off computer

6
From: Raed Sirhan

I have a server program that sends a lot of TCP messages to a group of clients (array of sockets), but I have a problem that the send() will hang up when sending many messages to a switched off computer (or to a computer that already disconnected from the network by cable or hub failure). I tried SO_KEEPALIVE but it takes a long of time before detecting that the socket was broken. so please, till what should I do to prevent the temporary hang up of the send() command

From: Vic Metcalfe

It seems to me that non blocking sockets would be a help here, but I don't have any good resources to point to for non blocking sockets. Its a topic I'd like to cover more in the faq, and add to the examples, but with other projects pressing for time it just hasn't been done. You might be able to do it by piecing together information from DejaNews. Good luck!   Vic.

From: Ian Berry

I have a similar problem, but I am using non-blocking sockets.
I am trying to create a simple server client using stream sockets where the server can handle the client stopping without properly closing the socket (in most cases i will be ctrl-c'ing the client).
In general everything works, unless you ctrl-c at the point when the server is doing a send to the client, at which point the server stops totally returning me to the prompt.
any thoughts?

From: Xidong Wang

you can catch the signal SIGINT, which is send to all the foreground processes by entering Ctrl-C.

From: Rob Seace

Yeah, but if he's seeing the SERVER process croak after
killing the client, while the server is trying to write to
the client, then the most likely problem is SIGPIPE that's
killing it, not SIGINT... (INT is killing the client, but
PIPE is most likely killing the server...) Personally, in
literally EVERY TCP/IP related program I write, one of the
first things I do is "signal (SIGPIPE, SIG_IGN);"... Then,
you don't get hit with SIGPIPE while writing to a closed
socket; but, instead, you get an error return from the
write, with errno set to EPIPE (which is a LOT easier to
deal with)... I believe this is all covered elsewhere in
this FAQ, too...

From: mahesha

I have TCP server and a client running,if the server dies
before client sends data then there no error reflected for the first time.However subsequently sendto fails.This happens only when MSG_NOSIGNAL flag is set,otherwise the
process exits.Why does send returns SUCCESS first time?how
do i catch the error first time?

Offline

Board footer

Powered by FluxBB