Establishing client-server communication
In this recipe, we will learn to make a client and will see how it can send messages to the server. The main idea is to understand how a message is sent, how the server listens to the port, and how communication is established between the two.
How to do it...
To send messages to the server, we will be making use of the Line Edit and Push Button widgets. The message written in the Line Edit widget will be passed to the server on the click of the push button. Here is the step-by-step procedure for creating a client application:
- Create another application based on the
Dialog without Buttonstemplate. - AddÂ
QLabel,QTextEdit,QLineEdit, andQPushButtonto the form by dragging and dropping theLabel,Text Edit,Line Edit, andPush Buttonwidgets on the form. - Set the
textproperty of theLabelwidget toClient. - Set the
textproperty of thePush Buttonwidget toSend. - Set the
objectNameproperty of theText Editwidget totextEditMessages. - Set the
objectNameproperty...