Socket qt -> java (android) [resolved]



  • I am trying to develop a client-server application.
    The server is Qt and Java client (android)
    I can receive data from the client.
    But when I send data to the client, receive it but not in the right format.

    Code C++
    @
    QByteArray paquet;
    QDataStream out(&paquet, QIODevice::WriteOnly);
    out << message; // On ajoute le message
    out << "\n";

    // Envoi du paquet préparé à tous les clients connectés au serveur
    for (int i = 0; i < clients.size(); i++)
    {
    clients[i]->write(paquet);
    }@

    Java code
    @in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    while(mRun) {
    Log.e(TAG, "En attente de message");
    mServerMessage = in.readLine();

    if(mServerMessage != null && mMessageListener != null){
    Log.e("REPONSE FROM SERVER", "S: Received Message: " + mServerMessage);
    mMessageListener.messageReceived(mServerMessage);
    }
    }@

    out
    @?N?E?W?C?L?I?E?N?T?@



  • Hi, you need to read the Qt documentation "Serializing Qt Data Types" if you want to manually parse the stream generated by QDataStream.



  • @QByteArray paquet = message.toUtf8 + '\n';
    // Envoi du paquet préparé à tous les clients connectés au serveur
    for (int i = 0; i < clients.size(); i++)
    {
    clients[i]->write(paquet);
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.