Re: TCP connection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Martijn for your response. I've got the W.R. Stevens's book. Yes, I checked the read(), it is not the read() problem, it is the server crashed and could no longer be blocked at select(). The accept / connect can be used for a client connection, but when a client program terminated or exit, the W.R. Stevens's book does not tell how to removed a terminated client, or I am missing something here?

Thank you.

Cheers.

Jim

Martijn van Oosterhout wrote:
On Wed, Oct 05, 2005 at 01:24:22PM +1000, YH wrote:

Hi,

Sorry, this is really not a linux question, rather a network programming question if you could still help me out:


Firstly, walk, nay, run to your nearest bookstore and pick up a copy of
UNIX Network Programming volume 1 by W.R. Stevens.


1. I have a server / client program of tcp connection on linux. The server uses a select function to wait clients packets. It works fine until a client program is terminated. Then the server is crashed (server program can no longer be blocked at select). How can the server detects the client terminate without crashing?


Do you check the result of read()? It will return an error when the
client closes it's end. If you don't do that you risk a SIGPIPE.


2. Is there any system function call or utilities on linux to check Ethernet and network status?


ifconfig, tcpdump, many many others.


3. Why we need to cast struct sockaddr_in serverAddress, clientAddress to struct sockaddr *) in bind(fd, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) and accept(fd, (struct sockaddr *)&clientAddress, &clientLength)?


Because bind and accept work for other protocols than IP, including
IPX, AX25, etc. So bind takes the generic type and you cast it when you
use it.

Hope this helps,

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux