void GuiServer::startServer()
{
//bool stat = server->listen(QHostAddress::Any, quint16(portEdit->text().toUShort()));
qDebug("%d", stat);
/* if(!stat)
QMessageBox::critical(this, "Error to bind port", "Fail to listen");
else
{
startButton->setEnabled(false);
stopButton->setEnabled(false);
}
*/
connect(server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); //Added
}
void GuiServer::incomingConnection(void)
{
QTcpSocket *client
= server
->nextPendingConnection
();
//modified
qDebug() << "New client from:" << client->peerAddress().toString();
connect(client, SIGNAL(readyRead()), this, SLOT(readMsg()));
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMsg()));
connect(client, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
void GuiServer::startServer()
{
//bool stat = server->listen(QHostAddress::Any, quint16(portEdit->text().toUShort()));
bool stat = server->listen(QHostAddress::Any, 5000);
qDebug("%d", stat);
/* if(!stat)
QMessageBox::critical(this, "Error to bind port", "Fail to listen");
else
{
startButton->setEnabled(false);
stopButton->setEnabled(false);
}
*/
connect(server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); //Added
}
void GuiServer::incomingConnection(void)
{
QTcpSocket *client = server->nextPendingConnection(); //modified
qDebug() << "New client from:" << client->peerAddress().toString();
connect(client, SIGNAL(readyRead()), this, SLOT(readMsg()));
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMsg()));
connect(client, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
To copy to clipboard, switch view to plain text mode
Bookmarks