服務器端:
connect(ui->enter,SIGNAL(clicked()),this,SLOT(enter()));
void Tuser::enter(){
ui->ipEdit->setEnabled(false);
ui->portEdit->setEnabled(false);
ui->label->setText("Please wait for another player...");
int x=ui->portEdit->text().toInt();
lserve->listen(QHostAddress::Any,x);
connect(lserve,SIGNAL(newConnection()),this,SLOT(start()));
}
void Tuser::start(){
//qDebug()<<"yes"; //沒有提示資訊列印出來,說明信號沒有發射
srand((int)time(0));
note=rand()%2;
init();//0:黑棋;1:白棋
two=lserve->nextPendingConnection();
connect(two,SIGNAL(readyRead()),this,SLOT(readmessage()));
sendmessage(1);
}
然后又查了客戶端:
void Ouser::enter(){
one->connectToHost(QHostAddress(ui->PipEdit->text()),ui->PportEdit->text().toInt());
if(!one->waitForConnected(30000)){
qDebug()<<one->errorString(); //這里列印出來Socket operation timed out。
}
else{
qDebug()<<"yes";
}
connect(one,SIGNAL(readyRead()),this,SLOT(readmessage()));
}
關于函式名相同的問題...Tuser 和Ouser是兩個工程,所以就是圖省事。
請問是跟網路狀況有關嗎?我把時間設成了30秒還是這個問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/111090.html
標籤:網絡通信
下一篇:衛星網路與adhoc網路
