QAbstractSocket is the base class for QTcpSocket and QUdpSocket and contains all common functionality of these two classes. If you need a socket, you have two options:
- 一。Instantiate QTcpSocket or QUdpSocket.
- 二。Create a native socket descriptor, instantiate QAbstractSocket, and call setSocketDescriptor() to wrap the native socket.
一,服务器采用多线程,继承QThread来构造TCPsocket,处理多个客户端。TCPSocket在incomingConnection内创建线程,并设置信号和槽,信号和信号关联,
最后启动thread->start(); 在run那里要 构建socket,同时要设置setSocketDescriptor。重要的是在线程接受大数据包要采用阻塞信号方式,确保处理完后在处理下一个数据包。
二,要确定IP和端口相一致,服务器的IP,要监听的端口socket
三,发送数据包形式是:数据包大小+数据包内容