To work with TCP / IP stack Qt provides QTcpServer, QTcpSocket, and QUdpSocket classes. For the first acquaintance with the work of the local network write Echo server. Task echo server to send back to the sender of the data obtained from it, as does the echo of a human voice. To connect to the server will be used telnet.
(TErminaL NETwork) — network protocol for the implementation of a text interface on the network (in modern form - using the TCP transport). The name «telnet» also have some tools that implement the client part of the protocol.
The proposed program
class object will listen to one of the
protocol stack ports from all hosts on the network. Listening port set by
indicating the specified IP-address, or IP-address range, as well as the listening port.
When a client connects to the port we invoke signal
, which will connects to slot
, the slot will be initiated by the client connection as
object on the server side using the method
, which returns a pointer to the object
Two slots will be connected to the new socket. First
slot is connected to the signal
from the socket, and will be called in if the socket on the data came, who are willing to read. The second slot
is connected to the signal
, which is called in the case when the client is disconnected from the server, and you must close the connection from the server side.
Project structure for work with QTcpServer
This will create a console application, so the classes like MainWindow in the annex will not be used.
- the profile of the project;
- the main source file;
- header file server;
- file server source code;