# Sockets; Servers and Clients

There is little point to the huge study of routing and network configuration if we can't move data from one host to another. This appendix will cover many of the command line tools (and a few daemons) which can be used to initiate TCP connections, receive TCP connections and send and receive UDP datagrams. Many of these tools are included with stock installations.

`telnet` and `nc` are the most common tools used for quickly creating a TCP connection. The less common utility `tcpclient` provides a scriptable method for initiating TCP sessions, equally as well as `nc`. Finally, the tool `socat` includes support for a large number of other types of sockets and files in addition to TCP and UDP.

Some services expect to run under another utility which will handle the socket operations. We'll tour the following utilities: `xinetd`, `tcpserver` and the very specifically designed port redirection utility `redir`.

It's important to remember that tools like `socat` and `nc` are suited equally well to initiate or receive TCP connections, but may not have the flexibility of administrative control afforded by tools such as `xinetd` and `tcpserver` where this was inherent to the design of the software.

## `telnet`

## `nc`

Quick example of `nc` (pronounced net-cat) in action.

### Simple use of `nc`

    [root@tristan]# nc 192.168.100.17 25
    220 isolde ESMTP
    quit
    221 isolde

`nc` is one of a large number of tools for making a simple TCP connection.

### Specifying timeout with `nc`

    [root@tristan]# nc -w 5 192.168.98.82 22

### Specifying source address with `nc`

    [root@masq-gw]# nc -s 192.168.99.254 192.168.47.3 25

### Using `nc` as a server

    [root@tristan]# nc -l -p 2048

### Delaying a stream with `nc`

    [root@tristan]# nc -l -p 2048

### Using `nc` with UDP

    [root@tristan]# nc -u 192.168.100.17 3000

## `socat`

### Simple use of `socat`

### Using `socat` with proxy connect

### Using `socat` perform SSL

### Connecting one end of `socat` to a file descriptor

### Connecting `socat` to a serial line

### Using a PTY with `socat`

### Executing a command with `socat`

### Connecting one `socat` to another one

## `tcpclient`

### Simple use of `tcpclient`

### Specifying the local port which `tcpclient` should request

### Specifying the local IP to which `tcpclient` should bind

## `xinetd`

### IP redirection with `xinetd`

### Publishing a service with `xinetd`

## `tcpserver`

### Simple use of `tcpserver`

### Specifying a CDB for `tcpserver`

### Limiting the number of concurrently accept TCP sessions under `tcpserver`

### Specifying a UID for `tcpserver`'s spawned processes

## `redir`

### Redirecting a TCP port with `redir`

Here we are going to talk about port redirection, so point out and .

### Running `redir` in transparent mode

### Running `redir` from another TCP server

### Specifying a source address for `redir`'s client side