We often use TCP and UDP connections in Internet communication.
TCP (Transmission Control Protocol) is connection-oriented, it tracks all data sent. By contrast, UDP (User Datagram Protocol) doesn’t care about datagrams it sent, all information is no sequencing. In other words, UDP is unreliable.
Both socket technologies can be used by the shell tool I described in this article.
The netcat utility can build TCP connection by default or send UDP packets with parameter -u.
Listen for UDP port 5009: nc -u -l 5009
.
Connect to UDP port: nc -u localhost 5009
.
The following video shows a simple example TCP connection created by netcat.
We can read the command’s introduction by man nc
on shell.
NC(1) BSD General Commands Manual NC(1)
NAME
nc -- arbitrary TCP and UDP connections and listens
SYNOPSIS
nc [-46AcDCdhklnrtUuvz] [-b boundif] [-i interval] [-p source_port]
[-s source_ip_address] [-w timeout] [-X proxy_protocol] [-x
proxy_address[:port]] [--apple-delegate-pid pid] [--apple-delegate-uuid uuid]
[--apple-ext-bk-idle] [--apple-nowakefromsleep] [--apple-ecn mode] [hostname]
[port[s]]
DESCRIPTION
The nc (or netcat) utility is used for just about anything under the sun involving
TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary
TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6. Unlike
telnet(1), nc scripts nicely, and separates error messages onto standard error
instead of sending them to standard output, as telnet(1) does with some.