分类: C/C++
2017-03-17 14:29:08
connect(&client_tcpsocket,SIGNAL(connected()),this,SLOT(slot_sendRequest()));
connect(&client_tcpsocket,SIGNAL(readyRead()),this,SLOT(slot_getResult())); connect(&client_tcpsocket,SIGNAL(disconnected()),this,SLOT(slot_connectionClosedByServer()));
connect(&server_tcpsocket,SIGNAL(disconnected()),this,SLOT(deleteLater()));
ManageServer myServer;
if(!myServer.listen(QHostAddress::Any,3679))
{
qDebug() << "Faile to bind to port";
return 1;
}else {
qDebug() << "Listening port 3679"; }
void Thread_client::slot_sendRequest()
{
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_8);
out << quint16(0)
<< client_UserName
<< client_PassWord;
out.device()->seek(0);
quint16 data_size = quint16(block.size() - sizeof(quint16));
out << data_size;
client_tcpsocket.write(block);
}
{
QDataStream in(&server_tcpsocket);
in.setVersion(QDataStream::Qt_4_8);
if(get_blocksize == 0)
{
if(server_tcpsocket.bytesAvailable() < sizeof(quint16))
return;
in >> get_blocksize;
}
if(server_tcpsocket.bytesAvailable() < get_blocksize)
return;
in >> userName;
in >> passWord;
}