QT-TCP.zip
使用QT,C++语言编写的 client与server通信,单纯的发送字符串通信。 #ifndef __SERVER_H #define __SERVER_H #include <QDialog> #include <QTcpServer> #include <QtNetwork> #include <QLabel> class QTcpServer; class Cserver : public QDialog{ Q_OBJECT public: explicit Cserver(QWidget *parent = 0); ~Cserver(); private: QTcpServer *m_tcpServer; QLabel *m_label; private slots: void sendMessage(); }; #endif //__SERVER_H #ifndef __CLIENT_H #define __CLIENT_H #include <QDialog> #include <QLabel> #include <QLineEdit> #include <QPushButton> #include <QAbstractSocket> #include <QString> #include <QtNetwork> class QTcpSocket; class CClient : public QDialog { Q_OBJECT public: explicit CClient(QWidget *parent = 0); ~CClient(); private slots: void newConnect(); void readMessage(); void displayError(QAbstractSocket::SocketError); private: QLabel *m_label_host; QLabel *m_label_port; QLabel *m_label_info; QLineEdit *m_lineEdit_host; QLineEdit *m_lineEdit_port; QPushButton *m_connectButton; QTcpSocket *m_tcpSocket; QString m_message; quint16 blockSize; }; #endif //__CLIENT_H