Results 1 to 8 of 8

Thread: Sockets: Send objects and Client/Server architecture

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Sockets: Send objects and Client/Server architecture

    Hi all,

    My goal is to create a (command line) server that handles multiple clients and provides a bunch of different functionality. It will have a DB (and i've already found the database examples around :P) to store data. Clients will request data from the serve, send new data to be added, send files to be processed and so on.

    I've already started looking at examples like the Threaded Fortune Server and Fortune Client, SQL browser and have some specifications and architecture design of what i want / need.

    The problem is my lack of knowledge about Qt (and C++ too). I'm more used to Java, have done stuff with C but i don't know how to send complex messages or even objects between clients and server. In Java i would/could send complex objects (Message for instance). I've seen by the examples how to send a simple string by convert it to a ByteArray, is this the correct way to go on more complex stuff?

    So i will just have the server waiting for strings that identify each desired action? How would i receive more complex calls that included parameters, for example get me info about books with "Qt" in title or Author. And how would i reply with vectors/arrays and objects? Is it the best/only option to send it string, int, etc. part by part in each message? :S

    Hope i'm being clear.
    Thanks in advance,
    PandMonium

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Sockets: Send objects and Client/Server architecture

    A couple of things I would recommend for your design:
    1. Don't use threads unless really really necessary. It will make your source code very complex.
    2. Don't use blocking sockets unless really really necessary. But since you're creating the server and the clients, you don't need them.
    3. Use QXmlStreamReader. You can use it to directly read xml messages from your socket. Using xml, you can send extremely complex commands and don't have to worry a great deal about parsing them.
    4. If you want to support multilingual messages, check your encodings. Try Utf8 for example.

  3. The following user says thank you to tbscope for this useful post:

    PandMonium (6th June 2010)

  4. #3
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sockets: Send objects and Client/Server architecture

    Before you reinvent the wheel have a look at some of the RPC (remote procedure call) protocols out there such as SOAP, XML-RPC, and REST. IF you do a search on each of these items with "QT" you should get Qt compatible libraries.

  5. The following user says thank you to numbat for this useful post:

    PandMonium (6th June 2010)

  6. #4
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sockets: Send objects and Client/Server architecture

    Thanks for replying

    So, is that 'the' solution? I've already used RPCs (Java RMI for instance) but not in C/C++ and wasn't expecting to use it here since i'm just trying to do a simple prototype for now (and already late :P).
    Picking the fortune client/server, if i wanted to get a list of (for example) persons with "Smith" in their name, how would i send the request and return something like a list of persons (with id, name, age)? In other words, is it possible to send more complex data over a socket?

    As for the RPC idea, Qt implements any of them? The idea is actually good but i feel that the extra time i would need to gain the knowledge / understand it, eventual problems and to make it work would kill my (already few) time left. No?

    Edit:
    Didn't saw the first reply to my post Anyway it is more or less the same, using RPC-XML would be good if i could get it working fast, don't want to encounter some big problems and lose extra time since i've few days to end this prototype (only the server). The QXmlDataStream might be the solution.
    About the threads, i don't plan to use them if not necessary. Obviously to have a server supporting multiple clients i will need one there. Other part would be in some routines doing serious audio/math processing that might take minutes. It uses an extra framework and my idea is to have its source in a separate thread and just launch a new one when i want to process something.
    Thanks again!
    Last edited by PandMonium; 5th June 2010 at 15:08.

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sockets: Send objects and Client/Server architecture

    Quote Originally Posted by PandMonium View Post
    So, is that 'the' solution?
    It's not Java, there is no "the" solution here. You can receive a similar effect using much different means.

    I've already used RPCs (Java RMI for instance) but not in C/C++ and wasn't expecting to use it here since i'm just trying to do a simple prototype for now (and already late :P).
    Picking the fortune client/server, if i wanted to get a list of (for example) persons with "Smith" in their name, how would i send the request and return something like a list of persons (with id, name, age)? In other words, is it possible to send more complex data over a socket?
    If you want something simple, have a look at QDataStream. I believe this is what the fortune cookie example uses as well.

    As for the RPC idea, Qt implements any of them?
    "Any of them" what? Qt is not Java, it's not a language, it's just a library that has *some* functionality and not *all the functionality in the world*. But you can use this library and other libraries together to obtain new possibilities.

    The idea is actually good but i feel that the extra time i would need to gain the knowledge / understand it, eventual problems and to make it work would kill my (already few) time left. No?
    I'm sorry but when in one sentence someone says "I lack knowledge in X" and in the next he says "I don't want to waste time learning" then I don't really see how anybody can help him. If you want a ready solution without spending time on learning then pay someone who already posseses this knowledge to do the job for you. Remember we are help to help you, not to do your job for you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #6
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sockets: Send objects and Client/Server architecture

    Nice bashing, do you feel better now??

    I'm not that good with english and may have explained incorrectly but i don't think i was rude or asked someone to do my work. Plus i don't see a point with that kind of reply, it is far from helping me out and just gives a bad impression about you/me/us to others visiting the forum. I think i know what Qt is and what Java is, i was just asking if Qt implements RPC-XML, SOAP or REST that i could use instead of researching for an extra library, just that.

    Explaining again, i've designed something and was starting to code it using Qt. It is something simple, just a prototype for now and planed to use sockets but the Fortune Client/Server just send a string and i decided to post hopping someone would give me their opinion on what was the better way to send more data at once (for example, 2 strings one float and an array of doubles). The first 2 posts were helpful and good suggestions but i was not expecting those suggestions (RPC). My later post was just to know more details about the RPC solution and sockets. I didn't complain about Qt or the suggestions and much less did i ask to someone do my work. This is just an academic -not paid- work and i have a few days to present my first prototype, using RPC would make me pass that deadline and change some of the plans i presented before.

    Anyway, for now i think i found the answer i was looking for in a book (Prentice Hall C++ GUI Programming with Qt 4), it looks simple with an example sending a bit more than just a string with a datastream/bytearray. I really appreciate all of your suggestions and will surely look at them once i've more time, after all they might be useful in other personal projects too.

    Hope i (we?) can be friendlier in the next topics

    Cya

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sockets: Send objects and Client/Server architecture

    Quote Originally Posted by PandMonium View Post
    Nice bashing, do you feel better now??

    I'm not that good with english and may have explained incorrectly but i don't think i was rude or asked someone to do my work. Plus i don't see a point with that kind of reply, it is far from helping me out and just gives a bad impression about you/me/us to others visiting the forum.
    An alternative would be that you received no response at all. I think it is better to have some kind of response that at least pushes the conversation a bit forward than to be ignored.

    I think i know what Qt is and what Java is, i was just asking if Qt implements RPC-XML, SOAP or REST that i could use instead of researching for an extra library, just that.
    It doesn't but there are other libraries that do.

    Explaining again, i've designed something and was starting to code it using Qt. It is something simple, just a prototype for now and planed to use sockets but the Fortune Client/Server just send a string and i decided to post hopping someone would give me their opinion on what was the better way to send more data at once (for example, 2 strings one float and an array of doubles). The first 2 posts were helpful and good suggestions but i was not expecting those suggestions (RPC). My later post was just to know more details about the RPC solution and sockets. I didn't complain about Qt or the suggestions and much less did i ask to someone do my work. This is just an academic -not paid- work and i have a few days to present my first prototype, using RPC would make me pass that deadline and change some of the plans i presented before.
    QDataStream, as already said.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #8
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sockets: Send objects and Client/Server architecture

    Indeed having a reply is always better and i appreciate all of them. I just thought your post could have been a bit nicer but saying the same things, after all bashing a new member/newbie without a big reason doesn't make the reply more helpful. I'm sorry if i didn't express well but i was not asking for someone to do my work, like i explained before.
    Anyway it ended being helpful since i've found a way of dong with DataStream and ByteArray, thanks to all for helping me out

Similar Threads

  1. tcp QT server - .Net c# client
    By soniaerm in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2010, 22:15
  2. Replies: 4
    Last Post: 2nd December 2008, 16:44
  3. how to send a file over qt4 tcp sockets?
    By sha3er in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2007, 16:57
  4. My client can't send data
    By hiuao in forum Qt Programming
    Replies: 10
    Last Post: 23rd February 2007, 09:32
  5. client-server how?
    By nongentesimus in forum Newbie
    Replies: 6
    Last Post: 28th November 2006, 09:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.