TCP and UDP basics: connecting to a website

I am just learning computer networks so please forgive me if this question is naive. I know the TCP protocol binds itself to a port till the transfer of messages is over (port 80) and UDP is best effort (ie no binding). My question is if I try and access two websites at the same time (multiple tabs on my browser), assuming both websites are web servers, my questions are

  1. Does my computer communicate with one webservice (website) first and then communicate with the other (serially). Also if this is the case is the time difference so small that I feel it loads simultaneously?

  2. Suppose I have my own web server (tomcat) running on port 80, how can I communicate with other websites if it happens on the same port?

  3. Do websites decide which protocol to use TCP or UDP?

I know the TCP protocol binds itself to a port till the transfer of messages is over (port 80)

A TCP connection is uniquely identified by the 4-tuple (source address, source port, dest address, dest port). The source and destination IP addresses will take care of themselves, but you’re slightly confused about the ports.

A port is just a 16-bit integer, used to distinguish between multiple active sockets on the same host, but there are certain conventions governing their allocation (reference: wikipedia):

  1. “well-known” ports are < 1024.

    These ports are generally protected by the OS, so an unprivileged process cannot bind one and hence masquerade as a well-known service.

    As you noted, 80 is the “well-known” port for HTTP, which means it’s the default unless your URL specifies otherwise.

  2. “registered” ports, useable by unprivileged processes to provide services, are between 1024 and 49152. For example, 8080 is commonly used for an unprivileged HTTP server

  3. remaining values from 49152 to 65535 are used for ephemeral ports. When you create a socket and connect to a server, without binding your socket to a particular local port, the kernel assigns a free port from the ephemeral range. This is just to create a unique 4-tuple identifying your connection, and you’ll normally never care what the value is.
    • NB. the actual range used for ephemeral ports may vary by OS and even be configurable – it’ll always start above 1024 though.

and UDP is best effort (ie no binding).

UDP stands for User Datagram Protocol. You’re right that it is best-effort, but that has nothing to do with ports. Both TCP and UDP use exactly the same IP addressing scheme, with the same 4-tuple. You’ll probably never use it for HTTP though (see the answer to your last question below).

My question is if I try and access two websites at the same time (multiple tabs on my browser), assuming both websites are web servers, my questions are

  1. Does my computer communicate with one webservice (website) first and then communicate with the other (serially). Also if this is the case is the time difference so small that I feel it loads simultaneously?

Yes and no. You create two sockets and connect them both. The source IP will be the same for each (since they’re on the same machine, and presumably using the same network interface on that machine). The destination IP and port will be the same (they’re connecting to the same HTTP server). The source port however will be different, because your OS allocated a different ephemeral port to each socket.

Because each socket is your endpoint for a different TCP connection (they have different unique 4-tuples), they can run in parallel. However, assuming as above the two connections are over the same physical network interface, they can’t send or receive physical packets simultaneously. In practise this doesn’t matter, since the OS will interleave their packets onto the physical network for you.

The connections will generally be asynchronous, so both sockets can have in-flight requests at once, and the replies can also be interleaved.

  1. Suppose I have my own web server (tomcat) running on port 80, how can I communicate with other websites if it happens on the same port?

Your website will be listening on the IP,port tuple (localhost,80). If you connect to it from the same machine, your connection will be something like (localhost, ephemeral1, localhost, 80). If you connect to a web server on a different machine, your connection will be something like (localhost, ephemeral2, remotehost, 80). They’re still different, even if they both have an 80 in one of the 4 values.

The only thing you can’t do is have two different web-servers both listening to port 80 on the same machine.

  1. Do websites decide which protocol to use TCP or UDP?

You can always check this stuff yourself: the standard is here. Here’s the relevant section:

HTTP communication usually takes place over TCP/IP connections. The
default port is TCP 80 [19], but other ports can be used. This does
not preclude HTTP from being implemented on top of any other protocol
on the Internet, or on other networks. HTTP only presumes a reliable
transport; any protocol that provides such guarantees can be used;
the mapping of the HTTP/1.1 request and response structures onto the
transport data units of the protocol in question is outside the scope
of this specification.

So you see HTTP doesn’t have to use TCP, but it does assume a reliable (and connection-oriented) protocol, so UDP is out.

4

Here are some basics for you to guide your learning.

Connections to Web servers are always TCP connections, and the port number is the port number on the server receiving the connection, not the client making the connection.

So:

  1. It is common for web browsers to make multiple connections to web servers at the same time. It’s considered good manners to not make more than 2 connections to the same server from the same client at any one time, but busy web servers will have hundreds (and even thousands) of simultaneous client connections.

  2. The local port used to connect to a remote server is generated randomly by your OS. It is not the same port number as the remote port you are connecting to, so there are no problems connecting to multiple web servers at the same time as running a web server locally.

  3. The protocol spoken by web servers are defined HTTP/1.0 and HTTP/1.1, and are specifically TCP connections.

4

Each TCP connection has 4 values to identify it: IP1 (own IP address), port1 (the port on my end), IP2 (the other computer’s address), port2 (the port on the other end).

As soon as any of these is different you are talking about a different connection. This creates a theoretical 4 billion TCP connections between any 2 computers. keeping this in mind:

  1. computers can have multiple connections active at the time (most of the time they’ll choose a different local port from the 65k available),

    you can even connect twice to the same server on the same port as long a the locally chosen port is different

  2. same as above, there is enough leeway in the local port range to open multiple connections, (though no-one will ever use 80 as the local port for outgoing connections)

  3. http (like 90% of all internet traffic) is over TCP,

    UDP is only used for specialist applications where you are allowed to lose some data

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật