Re: A tcp connetion question
> Sorry, I realize the segmentation fault was caused by perror(). After
> calling send(), the value of errno is 29, which caused perror() to crash
> whole process. Confused...
> However, that ain't problem. I just wanna know how to make client process
> detect such situations as server killed, network
> cable unplugged or anything else that can cause the disconnection?
Your segmentation fault indicates a bug in your program. perror()
doesn't normally crash even if the value of errno is 29 - you have tried
to write to some area that doesn't belong to you. Running the process
under gdb should tell you what caused the crash.
You detect such situations when recv() returns 0 (for an orderly
shutdown) or -1 (for an error).