Client-server architecture cheat-sheet

There are two types of users in client-server architecture:


Basic server creation and execution workflow:

Clients are created and used a lot easier:

Some points on working with client-server

Sockets based on Berkeley sockets can work in two modes: blocking and nonblocking.

Each side can suddenly terminate a session without correct signal to the opposite side (considering the protocol). For example, the network connection is gone or the computer is being taking away by enemies. In this case, reading/writing to the socket will return an error.

In case of a server, it is usually a good idea to keep more than one client connection simultaneously, for example, for network game players or streaming video viewers. Blocking calls will interfere with the program flow. The most common method in this case is:


If possible, one should always use a text message format for the protocol messages. Such protocols are easy to debug because they are human-readable. Text protocols are guaranteed to be portable: text is always text on any platform unlike binary data (consider byte order, size of data types etc). Such protocol could use, for example, XML or JSON as a base. Or it can be simple commands like in SMTP or FTP.

Designing protocols is more an art than a formal methods, but there are some general principles.