Chapter 9. Client-to-server Communication

In this chapter, we will discuss how to organize client-to-server communication. We will find answers to presumably the important questions, such as the right choice of Dart classes using the client-to-server communication. In this chapter, we will cover the following topics:

  • Communication at a glance
  • Hypertext Transfer Protocol
  • AJAX polling request
  • AJAX long polling request
  • Server-Sent Events
  • WebSocket

Communication at a glance

Some of us can't imagine the modern world without the Internet, cell phones, or computers. Each device connected to the Internet can either be a client, a server, or both of these simultaneously. Communication between a client and a server is the basis of modern digital world. Communication based on a system of special rules and format of messages is known as a communication protocol that enables data exchange between clients and servers.

The Internet protocol stack

Any device connected to the Internet has an Internet Protocol (IP) address. An IP address can be permanent or temporary when it is obtained from the Dynamic Host Configuration Protocol (DHCP) server. In any case, any device that is connected to the Internet has a unique IP address. Many programs working in scope of a single unique IP address use different port numbers to have access to the Internet simultaneously. A message transmitted from one device to another over the Internet is delivered through a long route via the protocol stack, which is represented as a set of layers that lie on top of one another as shown in the following diagram:

The Internet protocol stack

Let's see what actually happens with a message:

  1. A message arrives at the application protocol layer present on the top of the protocol stack, and then moves down. Usually, the application layer formats the message in one of the standard ways that is applicable to applications such as HTTP, SMTP, FTP, or others.
  2. The formatted message is then forwarded to the transmission control protocol (TCP) layer. It splits the message into small, manageable chunks of data known as packets and assigns a number to each of them. This number specifies the order of the packets and allows the recipient's TCP layer to reconstruct the original message from the packets. It assigns a port number to each packet, depending on the protocol being used at the application level.
  3. Then, these packets proceed to the IP layer. It attaches the IP address of the sender and recipient to each packet. A combination of the IP address and port number is called a socket address.
  4. Finally, a hardware layer attaches the Media Access Control (MAC) address of the sender and recipient to the packets. It allows the packets to be directed to a specific network interface on the IP address of the destination device. On the hardware layer, all packets are converted to electronic signals one by one, transmitted over the wire, and connected to the Internet Service Provider (ISP) modem.
  5. From here, it is the ISP's task to deliver packets of message to the specified IP address on the Internet via routers and ISP backbones.
  6. Packets delivered by the ISP start at the bottom of the protocol stack of the destination device. Any extra information stripped from the packets goes upwards.
  7. Eventually, data reaches the top of the stack where it is decoded into the original message.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.219.130