Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

server-client to SQLite please help



  • Hello
    I'm trying to make server-client to SQLite db

    Server: connects to the db and start QTCPServer

    Client: sends and receives query's via QTCPSocket

    The data that will be sent over the network will be in json format

    MyServer class : only listen to the new incoming connictions and when it do it opens new thread

    MyClient class: only make a static QTcpSocket and connect it to the server

    MyQuery class: sends the query's to the MyClient::socket->write()

    The problem is that i don't i know how much the query will take time to be executed and sent over the network so i can make socket->waitReadyread(time here) also if i made it a big period it will take too much time to execute a single query

    And if i made it with slot readyread() i don't know which myQuery object sent the query to the server

    So is there is any body here can help me with that



  • at your problem, I'll use tcpSocket::readyread()
    NOw the problems appear in your communication between your client and server. how do you communicate - keep in mind that using the TCP/Ip is a medium level of communication (low level is IP) you have to implement a hi level of protocol like HTML or FTP or IMAP and so on...
    what you need is:

    • to know that the user is a legit user
    • to verify the user with username and password
      -to make sure that all data has been received correctly

    when you make sure that the data has been transmitted correctly there are many options like CRC calculation or byte length and so on,...
    you can send something like: [byteLengts][data]
    [data] can be: [querryname] [ querry]
    so the client is sending
    [10][[querry1] [addToDatabase(field1, field1,fiel3)]]
    server response
    [3][[querry1] [ok]]

    client is sending:
    [5][[querry2] [select(tableName, fieldname=test)]
    server respond
    [400][[querry2][(record1 (field1, fiel2,field3) record2(fiel1,fiel2,fiel3).......)]]
    hope this help



  • oh, I've forgotten to tell you that on the server you just have to keep track of the client and the query that he sent and then you just reply back with that answer...

    answwerData processMySqlquerry(answerData clientRequest){
    //answerData can be a struct or a QMap or... whatever you want a class...
    //so you proccess the class/struct/qmap data from it
    if clientRequest.querry = select then
    return select from database-and make it back as answerData
    if  clientRequest.querry = Add then
    return add to database-and make it back as answerData
    //keep in mind that is answer data you have also a field called answerData.querryName witch has to be unique for all the communications between the client and server
    }
    


  • @arsinte_andrei ok thank you for the idea i will try to code and i faced any problems i will back


Log in to reply