QUdpSocket application



  • Hi,

    I want to make a datacollector that gets data from my device and put it in a mySql database. I know the protocol (udp based with seq.no and CRC16) for the device, and I know the Sql stuff. I could go with the QUdpsocket and ReadyData signal, but my device expect an acknowledge in return. I also have to accept a request for data from the Sql database from my device.

    The 2 protocol senarios:
    @
    Device: DataCollector:


    WriteData --> Store in SQL
    Acknowledge <-- Stored succesfull

    or

    Device: DataCollector:


    ReadData --> Retrieve from SQL
    Data + ACK <-- Data + retreived succesfull
    @

    So my question is: Is the sinal/slot approach the way to go or how would you solve this task ?

    Regards prosaicon



  • You could do either.

    If you want to send the data and receive in the same function, that's totally up to you. You would just need to send it, and call waitForReadyRead() after you send and pass in a timeout that way. Depeding how long the transaction takes and how long it takes your receiver to process/gather/send...if you do it this way, it might be better to do it in a thread and send updates to the ui via signals in slots so your not blocking your applications main thread for a extended amount of time. Just subclass a QThread.

    Another way would be to connect the ready read slot up to the socket, and have a QTimer for a timeout. When you send, if the data has not been received by the time the QTimer timeout fires, then you can display an error. Else, kill the timer in the ready read slot so it doesn't fire after successful transmission.

    You could also use a tcp socket...which will allow you to know that the connection to the receiver is successful.


Log in to reply
 

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