//server initialization
if(!success)
{
ui->textEdit->setTextColor(Qt::red);
ui->textEdit->append(" > Could not create TopMovie Server! \n Reason: TopMovie Server is already running! \n\n This Window will automatically close!");
ui->textEdit->setTextColor(Qt::black);
connect(timer, SIGNAL(timeout()), this, SLOT(sterge_server()));
timer->start(3000);
}
else
{
ui->textEdit->setTextColor(Qt::white);
ui->textEdit->append(" > TopMovie Server Online!");
connect(server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
ui->textEdit->setTextColor(Qt::black);
DataBase();
}
//incomingConnection
void TopMovieS::incomingConnection()
{
int Socketfd=server->nextPendingConnection()->socketDescriptor();
client->setSocketDescriptor(Socketfd);
clients.insert(client);
string adresa=" > New client from: "+client->peerAddress().toString().toStdString();
ui->textEdit->setTextColor(Qt::yellow);
ui->textEdit->append(adresa.c_str());
ui->textEdit->setTextColor(Qt::black);
connect(client, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(client, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
//server initialization
server= new QTcpServer();
bool success = server->listen(QHostAddress::Any, 10101);
if(!success)
{
ui->textEdit->setTextColor(Qt::red);
ui->textEdit->append(" > Could not create TopMovie Server! \n Reason: TopMovie Server is already running! \n\n This Window will automatically close!");
ui->textEdit->setTextColor(Qt::black);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(sterge_server()));
timer->start(3000);
}
else
{
ui->textEdit->setTextColor(Qt::white);
ui->textEdit->append(" > TopMovie Server Online!");
connect(server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
ui->textEdit->setTextColor(Qt::black);
DataBase();
}
//incomingConnection
void TopMovieS::incomingConnection()
{
int Socketfd=server->nextPendingConnection()->socketDescriptor();
QTcpSocket *client = new QTcpSocket(this);
client->setSocketDescriptor(Socketfd);
clients.insert(client);
string adresa=" > New client from: "+client->peerAddress().toString().toStdString();
ui->textEdit->setTextColor(Qt::yellow);
ui->textEdit->append(adresa.c_str());
ui->textEdit->setTextColor(Qt::black);
connect(client, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(client, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
To copy to clipboard, switch view to plain text mode
Bookmarks