【发布时间】:2014-01-30 19:04:58
【问题描述】:
void server::incomingConnection(qintptr socketDescriptor) {
qDebug() << "incoming connection";
connection* new_connection = new connection(this);
new_connection->set_socket_descriptor(socketDescriptor);
connect(new_connection, SIGNAL(ready_read()), this, SLOT(ready_read()));
connect(new_connection, SIGNAL(disconnected()), this, SLOT(disconnected()));
emit signal_new_connection(new_connection);
}
服务器类继承自QTcpServer,连接类 有一个 QTcpSocket 作为成员和一些关于想要的用户的信息 连接(名称,IP,ID ...)
我的问题是我对 new_connection 一无所知。我需要知道谁在连接服务器。出于这个原因,我想重新连接,但如何?有什么办法吗?还是必须等到我从连接的套接字(用户)收到数据(问候消息)?
【问题讨论】:
-
“谁在连接服务器”是什么意思?我认为您在问题中遗漏了一些信息。
-
我的意思是,我需要一个临时连接,在incomingConnection 函数之后初始化或者我可以在incomingConnection 函数中初始化new_connection? (对不起我的英语)
-
当然可以。但是你为什么不直接使用
nextPendingConnection()来获得一个连接良好的 QTcpSocket 呢? -
它们之间有主要区别吗?
标签: c++ qt sockets qtcpsocket qtcpserver