Vous êtes sur la page 1sur 7

How TCP/IP and UDP Works

TCP/IP is a suite of protocols used by devices to communicate over the Internet and most local
networks. It is named after two of its original protocolsthe Transmission Control Protocol (TCP)
and the Internet Protocol (IP). TCP provides apps a way to deliver (and receive) an ordered and error-
checked stream of information packets over the network. The User Datagram Protocol (UDP) is used
by apps to deliver a faster stream of information by doing away with error-checking. When
configuring some network hardware or software, you may need to know the difference.

What They Have In Common


Both TCP and UDP are protocols used for sending bits of dataknown as packetsover the Internet.
Both protocols build on top of the IP protocol. In other words, whether youre sending a packet via
TCP or UDP, that packet is sent to an IP address. These packets are treated similarly, as theyre
forwarded from your computer to intermediary routers and on to the destination.

An easy way to understand ports is to imagine your IP address is a cable box and the ports are the
different channels on that cable box. The cable company knows how to send cable to your cable box
based upon a unique serial number associated with that box (IP Address), and then you receive the
individual shows on different channels (Ports).

How TCP Works


TCP is the most commonly used protocol on the Internet.

When you request a web page in your browser, your computer sends TCP packets to the web servers
address, asking it to send the web page back to you. The web server responds by sending a stream of
TCP packets, which your web browser stitches together to form the web page. When you click a link,
sign in, post a comment, or do anything else, your web browser sends TCP packets to the server and
the server sends TCP packets back.

TCP is all about reliabilitypackets sent with TCP are tracked so no data is lost or corrupted in
transit. This is why file downloads dont become corrupted even if there are network hiccups. Of
course, if the recipient is completely offline, your computer will give up and youll see an error
message saying it cant communicate with the remote host.

TCP achieves this in two ways. First, it orders packets by numbering them. Second, it error-checks by
having the recipient send a response back to the sender saying that it has received the message. If
the sender doesnt get a correct response, it can resend the packets to ensure the recipient receives
them correctly.

Process Explorer and other system utilities can show the type of connections a process makeshere
we can see the Chrome browser with open TCP connections to a variety of web servers.
You can liken a TCP connection to a telephone connection.

With a telephone connection you first need to setup the connection by dialling the number, and
once the calling party answers you have a both way communications channel.

You then proceed to speak and once done you hang up the connection.

With TCP you set up the connection using the 3 way handshake as shown below:

The TCP transport takes care of errors on the link, and the application can be confident that the data
received is error free.
Just as with a telephone connection while you are using a connection no one else can use it. TCP is
used by application protocols that need guaranteed message delivery. HTTP, FTP, SMTP, POP3, IMAP4
and many other common Internet application protocols use TCP.

UDP- User Datagram Protocol


UDP is a connectionless protocol. You can liken UDP to email or the normal post. With email or a
written message you send your message, but have no idea whether or not that message was
received. UDP does not correct or recover errors in the message. Any error detection and recovery is
the responsibility of the receiving application.
Because there is no connection setup, UDP is faster than TCP and results in less network traffic. In
addition it doesnt consume resources on the receiving machine as it doesnt hold a connection
open. Utility applications like DNS, DHCP, RIP and others use UDP.

The use of UDP is expected to increase with IOT as sensor type data is ideal for sending via UDP.

How UDP Works


The UDP protocol works similarly to TCP, but it throws out all the error-checking stuff. All the back-
and-forth communication introduces latency, slowing things down.

When an app uses UDP, packets are just sent to the recipient. The sender doesnt wait to make sure
the recipient received the packetit just continues sending the next packets. If the recipient misses a
few UDP packets here and there, they are just lostthe sender wont resend them. Losing all this
overhead means the devices can communicate more quickly.

UDP is used when speed is desirable and error correction isnt necessary. For example, UDP is
frequently used for live broadcasts and online games.

For example, lets say youre watching a live video stream, which are often broadcast using UDP
instead of TCP. The server just sends constant stream of UDP packets to computers watching. If you
lose your connection for a few seconds, the video may freeze or get jumpy for a moment and then
skip to the current bit of the broadcast. If you experience minor packet-loss, the video or audio may
be distorted for a moment as the video continues to play without the missing data.

This works similarly in online games. If you miss some UDP packets, player characters may appear to
teleport across the map as you receive the newer UDP packets. Theres no point in requesting the old
packets if you missed them, as the game is continuing without you. All that matters is whats
happening right now on the game servernot what happened a few seconds ago. Ditching TCPs
error correction helps speed up the game connection and reduces latency.

So What?
Whether an application uses TCP or UDP is up to its developer, and the choice depends on what an
application needs. Most apps need the error-correction and robustness of TCP, but some applications
need the speed and reduced overhead of UDP.

Ports work the same way. You have an IP address, and then many ports on that IP address. When I
say many, I mean many. You can have a total of 65,535 TCP Ports and another 65,535 UDP ports.
When a program on your computer sends or receives data over the Internet it sends that data to an
ip address and a specific port on the remote computer, and receives the data on a usually random
port on its own computer. If it uses the TCP protocol to send and receive the data then it will connect
and bind itself to a TCP port. If it uses the UDP protocol to send and receive data, it will use a UDP
port. Figure 1, below, is a representation of an IP address split into its many TCP and UDP ports. Note
that once an application binds itself to a particular port, that port cannot be used by any other
application. It is first come, first served.
On a TCP/IP network every device must have an IP address.

The IP address identifies the device e.g. computer.

However an IP address alone is not sufficient for running network applications, as a computer can
run multiple applications and/or services.

Just as the IP address identifies the computer, the network port identifies the application or service
running on the computer.

The use of ports allows computers/devices to run multiple services/applications.

The diagram below shows a computer to computer connection and identifies the IP addresses and
ports.

Port Number Ranges


Well known ports (Port numbers0-1023) - These are allocated to server services by the Internet
Assigned Numbers Authority (IANA). E.g. Web servers normally use port 80 and SMTP servers use
port 25 (see diagram above).

Registered Port (Ports 1024-49151)-These can be registered for services with the IANA and should
be treated as semi-reserved. User written programs should not use these ports.

Ports 49152-65535 These are used by client programs and you are free to use these in client
programs. When a Web browser connects to a web server the browser will be allocated a port in this
range. Also know as ephemeral ports.
Sockets
A connection between two computers uses a socket.

A socket is the combination of IP address plus port

Each end of the connection will have a socket.

Imagine sitting on your PC at home, and you have two browser windows open, one looking at the
Google website, and the other at the Yahoo website. The connection to Google would be:

Your PC IP1+port 2020 Google IP2 +port 80 (standard port)

The connection to Yahoo would be:

Your PC IP1+port 2040 Yahoo IP3 +port 80 (standard port)

Notes: IP1 is the IP address of your PC. Client port numbers are dynamically assigned, and can be
reused once the session is closed.

Connection:
Network interface using UDP datagrams. In testing on the Odom boat, the HYPACK computer IP
address was set at 192.168.1.4.
Port Default is 56002.
Internet address 127.0.0.1 or address of the MB1 top side unit.

Vous aimerez peut-être aussi