This project is a simple example of a TCP message server written in C++. The server should listen on a given TCP port, receive messages from clients and print them to stdout. For every message received it should reply the client with "OK" message.
The message can contain any printable characters, \n caracter is a message delimiter. Maximum message length should not exceed 1024 characters (including delimiters).
Linux, g++, make
You can use make command in the terminal.
- Run server from the terminal using this command:
Server -p [port number]You can specify maximum timeout the server should work:Server -p [port number] -t [time in seconds] - Run one (or more) clients from a terminal using this command:
nc localhost [port number] - Type messages in the
ncprompt,enterkey (i.e.\n) can be used to finish a message. - You can terminate the server and clients at any time using
Ctrl + Ckeys combination or wait for the server to finish working after the specifyed timeout (-tflag)
- No under-load test was performed, only simple acceptance.
- No CLI was added to gracefully close the main(). You can only terminate it by kill signal (
Ctrl + C) or finish execution specifying a timeout. To be mentioned here, the implemented server object (class Server) do supports gracefull start and stop, please see the usage in main(). - Each new connection accepted will increase memory use by some small amount (yep, there's a leak), due to storage of all std::pthread objects. They will be released when the object is deleted.