The networking module in Qt is the module that offers both low-level networking functionality, such as TCP and UDP sockets, as well as high-level networking classes for web integration and network communication.
In this chapter, we will use the TCP (Transmission Control Protocol) internet protocol for our program instead of the UDP (User Datagram Protocol) protocol. The main difference is that TCP is a connection-oriented protocol that requires all clients to establish a connection to the server before they are able to communicate with each other.
UDP on the other hand is a connectionless protocol that does not require a connection. The client will just send whatever data it needs to send to the destination, without checking if the data has been received by the other end. There are pros and cons for both protocols, but TCP is much more suitable for our sample project. We want to make sure every chat message is being received by the recipient, don't we?
The differences between both protocols are as follows:
- TCP:
- Connection-oriented protocol
- Suitable for applications that require high reliability, and it is less critical toward its data transmission time
- The speed for TCP is slower than UDP
- Requires acknowledgment of receipt from the receiving client before sending the next data
- There is an absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent
- UDP:
- Connectionless protocol
- Suitable for applications that need fast, efficient transmission, such as games and VOIP
- UDP is lightweight and faster than TCP because error recovery is not attempted
- Also suitable for servers that answer small queries from huge numbers of clients
- There is no guarantee that the data sent reaches its destination at all as there is no tracking connections and no need for any acknowledgment from the receiving client
Since we are not going for the peer-to-peer connection approach, our chat system will require two different pieces of software—the server program and the client program. The server program will act as the middleman (just like a postman) who receives all the messages from all the users and sends them to the targeted recipients accordingly. The server program will be locked away from the normal users in one of the computers in the server room.
The client program, on the other hand, is the instant messaging software that is used by all the users. This program is the one that is being installed on the users' computers. Users can send their messages using this client program and see the messages sent by others as well. The overall architecture of our messaging system looks something like this:
![](Images/26bb7700-45cf-4482-9232-4eb2ce750839.png)
Let's proceed to setting up our project and enabling Qt's networking module! For this project, we will start on the server program before working on the client program.