What is a network?
How the client and server exchange data
The articles written on this blog were created with the goal of teaching. Also, the information in the article may be incorrect, so please be careful.
A network is a structure in which remote computers exchange data according to established rules. Online games, web browsers, and chat programs also basically start with the process of sending data and receiving a response.
Find a program by address and port
An IP address is an address used to find a computer on a network. The port number identifies which program will communicate with the computer.
192.168.0.10:7777
└─ IP address └─ Port
The server waits for a request on a specific port, and the client attempts to connect to the server's address and port. After connection, both sides exchange messages in the promised format.
Protocols are the rules for data exchange
Just by looking at the bytes sent, you can't tell whether it's a login request or a character location. So, the message type, length, and order of values are determined in advance.
[Message Type][Data Length][Actual Data]
[MOVE ][12 ][x, y, z]
This promise is called a protocol. If the server and client do not use the same rules, they cannot be interpreted properly.
TCP and UDP
TCP ensures that data arrives in order and resends if it is lost. It is good for tasks where accuracy is important, such as file transfer, logging in, and chatting.
UDP has simple connection and retransmission management, making it easy to reduce delay. Instead, data may disappear or change order, so the program must determine what reliability handling is needed.
TCP: Prioritizes accurate delivery.
UDP: Good for prioritizing fast delivery and up-to-date status.
Online games need to hide lag
Network data does not arrive immediately. Prediction and interpolation are used to make the client screen smooth, and important decisions are often made in a structure where the server makes the final decision.
The beginning of network programming is not complicated synchronization. It's a good idea to start with a small Echo program where a client sends a string and the server returns the same string, checking connections, messages, and error handling.