Beispiel #1
0
void TcpGateDialog::InitConnect()
{
	m_ndConnect.group = ui->gbConnect;
	m_ndConnect.cbIp = ui->cbCIP;
	m_ndConnect.spinPort = ui->spinCPort;
	m_ndConnect.lnSend = ui->lnCSendBytes;
	m_ndConnect.lnRecv = ui->lnCRecvBytes;
	m_ndConnect.leStatus = ui->leCStatus;
	m_ndConnect.btnStart = ui->btnConnect;	
	connect(m_ndConnect.btnStart, SIGNAL(clicked()), this, SLOT(onClkBtnConnect()));
		
	m_ndConnect.bConnected = false;
	m_ndConnect.bStarted = false;
	m_ndConnect.nSendBytes = 0;
	m_ndConnect.nRecvBytes = 0;	
	QSettings setting;
	m_ndConnect.latestIpList = setting.value("TcpGateTest/Connect/LatestIP", "").toStringList();
	int nCount = m_ndConnect.latestIpList.count();
	for (int i = nCount-1; i >= 0; i--)
	{
		if (!m_ndConnect.latestIpList[i].isEmpty())
		{
			m_ndConnect.cbIp->addItem(m_ndConnect.latestIpList[i]);
		}
	}
	
	m_ndConnect.tcpServer = NULL;	
	m_ndConnect.tcpSocket = new QTcpSocket(this);
	m_ndConnect.spinPort->setValue(setting.value("TcpGateTest/Connect/LatestPort", 5100).toInt());	
	connect(m_ndConnect.tcpSocket, SIGNAL(connected()), this, SLOT(onConnected()));
	connect(m_ndConnect.tcpSocket, SIGNAL(disconnected()), this, SLOT(onDisConnected()));
	connect(m_ndConnect.tcpSocket, SIGNAL(readyRead()), this, SLOT(onRead()));
	connect(m_ndConnect.tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
		this, SLOT(onNdcError(QAbstractSocket::SocketError)));
}
Beispiel #2
0
TcpSocketThread::TcpSocketThread(QObject *parent) :
    QThread(parent)
{
    bStop = false;
    m_bConnected = false;

    connect(&m_qTcpSocket, SIGNAL(connected()), this, SLOT(onConnected()));
    connect(&m_qTcpSocket, SIGNAL(disconnected()), this, SLOT(onDisConnected()));
    connect(&m_qTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(quit()));
    //connect(&m_qTcpSocket, SIGNAL(readyRead()), this, SLOT(tcpSocketRecvData()));

    if (!m_bConnected)
    {
        m_qTcpSocket.connectToHost(host, port);
        m_qTcpSocket.waitForConnected(10);
        //sleep(5);
    }
}
Beispiel #3
0
void TcpGateDialog::onNewConnection()
{
	if(m_ndListen.tcpSocket)
	{
		m_ndListen.tcpSocket->close();
		delete m_ndListen.tcpSocket;
	}
	
	m_ndListen.tcpSocket = m_ndListen.tcpServer->nextPendingConnection();
	connect(m_ndListen.tcpSocket, SIGNAL(disconnected()), this, SLOT(onDisConnected()));
	connect(m_ndListen.tcpSocket, SIGNAL(readyRead()), this, SLOT(onRead()));
	connect(m_ndListen.tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
		this, SLOT(onError(QAbstractSocket::SocketError)));
	
	Log2Main(tr("receive new connect%1:%2").arg(m_ndListen.tcpSocket->peerAddress().toString()).arg(m_ndListen.tcpSocket->peerPort()));
	
	m_ndListen.bConnected = true;
}