Ejemplo n.º 1
0
/**
 *函数介绍:有请求连接,新建一个socket
 *输入参数:int socketId,新建socket的SocketDescriptor
 *返回值:无
 */
void TcpServer::incomingConnection(int socketId)
{
    TcpSocket *socket = new TcpSocket(socketId,this);
	//设置socket描述符
    socket->setSocketDescriptor(socketId);
	//写入系统日志
	//Global::systemLog->append(tr("网络通信服务端有新的连接请求"), QString(tr("服务端接收新的连接请求,socket描述符 = %1.")).arg(socketId), SystemLog::INFO);

    qDebug()<<"服务端有新的连接,socketDescriptor:"<<socket->socketDescriptor();
    //新建了一个socket连接
    addServerSocket(socketId);


    //获得客户端数据
    connect(socket, SIGNAL(haveReadDataSignal(QByteArray,int)), this, SLOT(getClientMessage(QByteArray,int)));
	//信号槽:跟踪服务端Socket状态
    connect(socket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(getServerSocketState(QAbstractSocket::SocketState)));
    //信号槽:服务端socket出现错误
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverSocketError(QAbstractSocket::SocketError)));

    //与客户端断开某socket连接,服务端状态发生改变
    connect(socket, SIGNAL(disconnectedBeforeDeleteSignal(int)), this, SLOT(removeServerSocket(int)));
    //与客户端断开连接,输出服务器当前连接
    //connect(socket, SIGNAL(disconnectedBeforeDeleteSignal(int)), this, SLOT(getAllConnection()));	
	//与客户端连接上后,输出服务器当前连接
    //connect(socket, SIGNAL(connectedForServerSignal(int)), this, SLOT(getAllConnection()));
    //与客户端连接上后,输出服务器当前连接
    //connect(socket, SIGNAL(connectedForServerSignal(int)), this, SLOT(addServerSocket(int)));

}
Ejemplo n.º 2
0
void NfcPeerToPeer::handleNewConnection()
{
    if (!m_connectServerSocket)
        return;

    if (m_nfcServerSocket) {
        m_nfcServerSocket->deleteLater();
    }

    // The socket is a child of the server and will therefore be deleted automatically
    m_nfcServerSocket = m_nfcServer->nextPendingConnection();

    connect(m_nfcServerSocket, SIGNAL(readyRead()), this, SLOT(readTextServer()));
    connect(m_nfcServerSocket, SIGNAL(error(QLlcpSocket::SocketError)), this, SLOT(serverSocketError(QLlcpSocket::SocketError)));
    connect(m_nfcServerSocket, SIGNAL(stateChanged(QLlcpSocket::SocketState)), this, SLOT(serverSocketStateChanged(QLlcpSocket::SocketState)));
    connect(m_nfcServerSocket, SIGNAL(disconnected()), this, SLOT(serverSocketDisconnected()));

    if (m_reportingLevel != AppSettings::OnlyImportantReporting) {
        emit statusMessage("New server socket connection");
    }
    sendCachedText();
}