Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ TCP(7P) — HP-UX 9.03

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getsockopt(2)

socket(2)

inet(7F)

TCP(7P)

NAME

TCP − Internet Transmission Control Protocol

SYNOPSIS

#include <sys/socket.h>
#include <netinet/in.h>

s = socket(AF_INET, SOCK_STREAM, 0);

DESCRIPTION

The TCP protocol provides reliable, flow-controlled, two-way transmission of data.  It is a byte-stream protocol used to support the SOCK_STREAM socket type.  TCP constructs virtual circuits between peer entities.  A virtual circuit consists of remote Internet addresses, remote ports, local Internet addresses and local ports.  IP uses the Internet addresses to direct messages between hosts, and the port numbers to identify a TCP entity at a particular host. 

Sockets using TCP are either active or passive.  connect() creates active sockets, which initiate connections to passive sockets (see connect(2)). To create a passive socket, use the listen() system call after binding the socket with the bind() system call (see listen(2) and bind(2)). Only passive sockets can use the accept() call to accept incoming connections (see accept(2)).

Passive sockets can underspecify their location to match incoming connection requests from multiple networks.  This technique, called wildcard addressing, allows a single server to provide service to clients on multiple networks.  To create a socket that listens on all networks, the Internet address INADDR_ANY must be bound.  The TCP port can still be specified even if wildcard addressing is being used.  If the port is specified as zero, the system assigns a port. 

Once accept() has a rendezvous with a connect request, a virtual circuit is established between peer entities.  bind() supplies the local port and local Internet address and accept() gathers the remote port and remote Internet address from the peer requesting the connection. 

The system supports one socket option, TCP_NODELAY (defined in the include file <netinet/tcp.h>), which is set with setsockopt() and tested with getsockopt(), and is explained below (see getsockopt(2)):

TCP_NODELAY (boolean option; TCP SOCK_STREAM sockets only) causes small amounts of output to be sent immediately. 

If TCP_NODELAY is set, the system sends small amounts of output immediately rather than gathering them into a single packet after an acknowledgement is received.  If TCP_NODELAY is not set, the system sends data when it is presented, if there is no outstanding unacknowledged data.  If there is outstanding unacknowledged data, the system gathers small amounts of data to be sent in a single packet once an acknowledgement is received.  For clients such as window managers that send a stream of mouse events which receive no replies, this packetization may cause significant delays.  The TCP_NODELAY option can be used to avoid this situation.  Note, however, that setting the TCP_NODELAY option may result in a large number of small packets being sent over the network. 

The default when a socket is created is that TCP_NODELAY is not set. 

The option level to use for accessing the TCP option with the setsockopt() or getsockopt() calls is the protocol number for TCP which is available from getprotobyname() (see getprotobyname(3N)).

DIAGNOSTICS

One of the following errors may be returned if a socket operation fails.  See the manual entry for the specific system call for a more complete and specific list of errors. 

[EISCONN] Attempt to establish a connection on a socket which already has one, or attempted operation on a connected socket that can only be done on one that has not been connected. 

[ENOBUFS] System ran out of memory for an internal data structure. 

[ETIMEDOUT] Connection dropped due to excessive retransmissions. 

[ECONNRESET] Remote peer forces the connection to be closed. 

[ECONNREFUSED] Remote peer actively refuses connection establishment (usually because no process is listening to the port). 

[EADDRINUSE] Attempt create a socket with a port that has already been allocated. 

[EADDRNOTAVAIL] Attempt to create a socket with a network address for which no network interface exists. 

DEPENDENCIES

This entry describes the use of the TCP protocol as it applies to the ARPA Services Inter-Process Communication utility.  It does not apply to the use of TCP for the LAN/9000 Net IPC utility on HP 9000 systems.  Refer to the HP 9000 NetIPC Programmer’s Guide for information about Net IPC. 

If the SO_KEEPALIVE option is set on an established TCP connection, and the connection has been idle for two hours, TCP sends a packet to the remote socket, expecting the remote socket to acknowledge that it is still alive.  If the remote socket does not respond within 75 seconds, TCP sends another packet.  If TCP sends a total of 8 packets without response from the remote socket (that is, 10 minutes have passed), TCP drops the connection and the next socket call (e.g., recv()) returns an error with errno set to ETIMEDOUT.  See getsockopt(2) for details on setting SO_KEEPALIVE. 

The maximum buffer size for a TCP stream socket is 58254 bytes. The default buffer size is 8192 bytes. The send and receive buffer sizes for TCP stream sockets can be altered by using the SO_SNDBUF and SO_RCVBUF options of the setsockopt() system call.  Refer to getsockopt(2) for details.

AUTHOR

TCP was developed by the University of California, Berkeley. 

SEE ALSO

getsockopt(2), socket(2), inet(7F). 

Hewlett-Packard Company  —  HP-UX Release 9.03: April 1994

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026