TCP/IP Client-Server приложение на платформе QtCreator(C++)

у меня возник вопрос по поводу удалённого Client-Server взоимодействия. Client приложение отлично подключается когда и сервер и клиент работают на одной машине (IP 127.0.0.1, Порт 5555) ,но даже в локальной сети подключатся не получается. Возможно ли подключится например в локальной и/или глобальной сети?

#include "Server.h"
Server::Server(){//Server user-defined constructor

}

Server::~Server(){//Server default destructor

}

void Server::startServer(){//called when server starts working
    qDebug()<< "Stex"<<'\n';
    if (this->listen(QHostAddress::Any, 80)){
        qDebug()<< "LISTENING!!"<<'\n';
    }
    else qDebug()<< "NOt Listening"<<'\n';
}

void Server::BackUP(){
    ofstream BackUp("C:\\Users\\НеВажно\\Documents\\BDServer\\BackUp.txt");
    system("cls");
    BackUp << showRecentClients().toStdString();

}
Server::CLIENT::CLIENT(QString name){
    ::userSerialNumber ++;
    selfSerialNumber = :: userSerialNumber;
    this->name = name;
}
Server::CLIENT::~CLIENT(){

}

QString Server::CLIENT::ShowConditions(){//defining show condition of current socket

    return +"|Client N  :"    +QString::number(this->selfSerialNumber)
           +"   |TOKEN  :"    +this->TOKEN
           +"   |STATUS :"    +(this->STATUS == false ? "NOT CONNECTED" : "CONNECTED")
           +"   |IP_v4  :"    +(this->IP_v4.toString())
           +"   |PERMISSION :"+(this->Permission);

}

QString Server::showRecentClients(){//show  conditions of recent connected clients
    QString MAINSTRING;
    qDebug()<< "\n\n_______RECENT_____CLIENTS_____";
    for (int i = 0 ; i < CLIENTSet.size(); ++i){
        qDebug() << CLIENTSet[i].ShowConditions();
        MAINSTRING +=( CLIENTSet[i].ShowConditions() + '\n');
    }
      qDebug()<< "_______RECENT_____CLIENTS_____\n\n";
      return MAINSTRING;
}

void Server::incomingConnection(int socketDescriptor){                                      //called when incoming signal from 5555 port detected

    CLIENT *newCLIENT = new CLIENT();                                                       //create new client
    newCLIENT->selfSerialNumber = userSerialNumber;                                         //set new client serial number
    newCLIENT->socket = new QTcpSocket(this);                                               //create new socket for new client
    CLIENTSet.push_back(*newCLIENT);                                                        //add new client to recent clients set   <CLIENTSet>
    newCLIENT->socket->setSocketDescriptor(socketDescriptor);                               //.........................................
    connect(newCLIENT->socket, SIGNAL(readyRead()),this,SLOT(sockReady()));                 //bind function readyRead() with sockReady()
    connect(newCLIENT->socket,SIGNAL(disconnected()),this, SLOT(sockDisc()));               //bind funtcion disconnected() with sockDisc()
    CLIENTSet[CLIENTSet.size()-1].STATUS =  CLIENTSet[CLIENTSet.size()-1].socket->isOpen(); //set new client status wether it open or not
    if ( CLIENTSet[CLIENTSet.size()-1].socket->isOpen()){
        qDebug() << "New Connection ... ";
    }

}

void Server::sockReady(){//called when sockt is ready to send/recieve Bytes
    CLIENTSet[CLIENTSet.size()-1].TOKEN = CLIENTSet[CLIENTSet.size()-1].socket->readAll();//get Token from client
    CLIENTSet[CLIENTSet.size()-1].IP_v4 = CLIENTSet[CLIENTSet.size()-1].socket->peerAddress();//get IP_v4 address from client
    if (CLIENTSet[CLIENTSet.size()-1].TOKEN.isEmpty()) {
        CLIENTSet[CLIENTSet.size()-1].TOKEN = DEFAULT;
        qDebug() << "TOKEN IS EMPTY\n";
    }
    if (CLIENTSet[CLIENTSet.size()-1].TOKEN == this->rootTOKEN)
          CLIENTSet[CLIENTSet.size()-1].Permission = Zero;//if token ,sended from client , is equal to rootTOKEN , give client ROOT (Zero) Permission

    else if (CLIENTSet[CLIENTSet.size()-1].TOKEN == this->userTOKEN)//if token ,sended from client , is equal to userTOKEN , give client USER (One) Permission
          CLIENTSet[CLIENTSet.size()-1].Permission = One;

    else CLIENTSet[CLIENTSet.size()-1].Permission = Two;//if given token is not equal given above tokens give client guest permission
}


void Server::sockDisc(){//called when socket disconnects from slot
    CLIENTSet[CLIENTSet.size()-1].socket->close();//close socket to ac
    CLIENTSet[CLIENTSet.size()-1].STATUS  = false;
    CLIENTSet[CLIENTSet.size()-1].ShowConditions();//show condidition of the last connected client
    BackUP();//backup all recent connected clients when the last client disconnected
}

Ответы (0 шт):