Beispiel #1
0
Client::Client(QTcpSocket* socket, QObject* parent) :
    QObject(parent), m_socket(socket), tailleMessage(0)
{
    messageHandler = new MessageHandler(this);
    connect(socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
}
Beispiel #2
0
void Client::donneesRecues()
{
    QDataStream stream(m_socket);

    //Récupération de la taille du paquet
    if (m_taillePaquet == 0)
    {
        if (m_socket->bytesAvailable() < sizeof m_taillePaquet)
            return;

        stream >> m_taillePaquet;
    }

    //Récupération du reste du paquet
    if (m_socket->bytesAvailable() < m_taillePaquet)
        return;

    //On lit la socket pour la taille d'un paquet et on stocke.
    Paquet *in = new Paquet(m_socket->read(m_taillePaquet));

    //Remise à zéro de la taille du paquet
    m_taillePaquet = 0;

    //On envoie le paquet reçu
    emit paquetRecu(in);

    //S'il nous reste quelque chose dans la socket, on relance la fonction.
    if (m_socket->bytesAvailable())
        donneesRecues();
}
Beispiel #3
0
void FenServeur::nouvelleConnexion()
{
    envoyerATous(tr("<em>Un nouveau client vient de se connecter</em>"));

    QTcpSocket *nouveauClient = serveur->nextPendingConnection();
    clients << nouveauClient;

    connect(nouveauClient, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(nouveauClient, SIGNAL(disconnected()), this, SLOT(deconnexionClient()));
}
Beispiel #4
0
Client_Utils::Client_Utils(QTextEdit *liste) {
    listeMessages = liste;
    socket = new QTcpSocket(this);
    connect(socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(socket, SIGNAL(connected()), this, SLOT(connecte()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(deconnecte()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurSocket(QAbstractSocket::SocketError)));

    tailleMessage = 0;
}
Beispiel #5
0
void MainWindow::status_connecte(char *toto){
    statusBar()->showMessage(tr(toto));
    if (etat_serveur_port){
        serveurConnect->setText("Connected");
        serialGroupBox->setTitle("Port série distant");
        QObject::connect(servv, SIGNAL(dataReadyRead()), servv, SLOT(donneesRecues()));
        QObject::connect(servv, SIGNAL(dataServerReceived()), this, SLOT(readData()));
        }
    else{
        serveurConnect->setText("Disconnected");
        serialGroupBox->setTitle("Port série local");
    }
}
Beispiel #6
0
/**
 * @brief serveur::newConnexion
 */
void serveur::newConnexion()
{
    //envoyerATous(tr("<em>Un nouveau client vient de se connecter</em>"));

    QTcpSocket *nouveauClient = server->nextPendingConnection();
    clients << nouveauClient;

    connect(nouveauClient, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(nouveauClient, SIGNAL(disconnected()), this, SLOT(deconnexionClient()));

    QTime current = QTime::currentTime();
    log->append(QString("["+ (current.toString("HH:mm.ss a")) +"] : Connexion d'un nouveau joueur' "));
}
Beispiel #7
0
Cmd::Cmd(QObject *parent) :
    QObject(parent), boucle(true), tailleMessage(0), out(stdout, QIODevice::WriteOnly), in(stdin, QIODevice::ReadOnly)
{
    m_socket = new QLocalSocket(this);
    connect(m_socket, SIGNAL(connected()), this, SLOT(onConnexion()));
    connect(m_socket, SIGNAL(disconnected()), this, SLOT(onDeconnexion()));
    connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(onError(QLocalSocket::LocalSocketError)));
    connect(m_socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)), this, SLOT(onStateChanged(QLocalSocket::LocalSocketState)));
    connect(m_socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    m_socket->connectToServer("CrafterServer");
    out << tr("demarrage\n");

    connect(this, SIGNAL(quit()), qApp, SLOT(quit()));
}
Beispiel #8
0
FenClient::FenClient()
{
    setupUi(this);

    socket = new QTcpSocket(this);
    connect(socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(socket, SIGNAL(connected()), this, SLOT(connecte()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(deconnecte()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurSocket(QAbstractSocket::SocketError)));
    //connect(checkBox, SIGNAL(stateChanged(int)),this, SLOT(coche()));//lance coche() si on choche la case
    //connect(checkBox, SIGNAL(stateChanged(int)),this, SLOT(decoche()));//lance decoche() si on déchoche la case
    //connect(pushButton, SIGNAL(clicked()),this, SLOT(pushAction()));//lance pushAction() si on lance l'action 2
    tailleMessage = 0;
}
interSocketClient::interSocketClient(QString address, int port, FenGenerale *parent) : m_sem(0), m_stockage(""),
    QMainWindow(parent)
{
    m_IG = parent;
    m_socket = new QTcpSocket;
    m_socket->connectToHost(address, port);

    connect(m_socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(m_socket, SIGNAL(connected()), this, SLOT(connecte()));
    connect(m_socket, SIGNAL(disconnected()), this, SLOT(deconnecte()));
    connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurSocket(QAbstractSocket::SocketError)));

    m_tailleMessage = 0;
}
Beispiel #10
0
FenClient::FenClient(QWidget *parent) :
            ui(new Ui::FenClient)
{
    ui->setupUi(this);

    socket = new QTcpSocket(this);

    connect(socket,SIGNAL(readyRead()),this,SLOT(donneesRecues()));
    connect(socket,SIGNAL(connected()),this,SLOT(connecte()));
    connect(socket,SIGNAL(disconnected()),this,SLOT(deconnecte()));
    connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(erreurSocket(QAbstractSocket::SocketError)));
    connect(ui->pseudo,SIGNAL(textEdited(QString)),this,SLOT(pseudoObligatoire()));
    tailleMessage=0;
    ui->boutonEnvoyer->setEnabled(false);
}
Beispiel #11
0
Client::Client(QTcpSocket *socket, FenPrincipale *parent) : m_parent(parent), m_socket(socket), m_taillePaquet(0), m_pseudo(""), m_account(""), m_loginLevel(0),
m_idCompte(0), m_logoutMessage(""), m_sessionState(NOT_CHECKED), m_channel(0), m_pingsPending(0), m_ping(0)

{
    connect(m_socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
    connect(m_socket, SIGNAL(disconnected()), this, SLOT(deconnexion()));

    //Création du timer pour le lancement des pings.
    m_pingTimer = new QTimer(this);
    connect(m_pingTimer, SIGNAL(timeout()), this, SLOT(sendPing()));
    m_pingTimer->start(m_parent->getPingInterval());
    sendPing(); //On lance un ping

    //Génération du hash de l'IP.
    //4 caractères hexa.
    m_hashIP = QCryptographicHash::hash(m_socket->peerAddress().toString().toUtf8(),
                                        QCryptographicHash::Md5).toHex().left(4);
}
Beispiel #12
0
void RollitWidget::setPlayByNetwork(bool bo,QString iptxt,quint16 p)
{
qDebug()  << "playbynetwork" << bo;
playbynetwork=bo;

socket = new QTcpSocket(this);

QHostAddress ad(iptxt);


socket->connectToHost(ad,p,QIODevice::ReadWrite);
connect(socket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
connect(socket, SIGNAL(connected()), this, SLOT(connecte()));
connect(socket, SIGNAL(disconnected()), this, SLOT(deconnecte()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurSocket(QAbstractSocket::SocketError)));

tailleMessage = 0;



return;


}
void fenetre_bc::nouvelleConnexion()
{
    QTcpSocket *nouveauClient = serveur->nextPendingConnection();
    liste<<nouveauClient;
    connect(nouveauClient, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
}