CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Query database via winsock

  1. #1
    Join Date
    Mar 2000
    Posts
    66

    Query database via winsock

    I am developing a client/server app using winsock, and I need the client to query a database. I realize that I can cast structures to a char* buffer and send them.

    My question is, do my structures need to contain only "built-in" types like char, int, ect., or can they also contain other objects like ADO's recordset (_RecordsetPtr)?

    Thanks

  2. #2
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354
    The structure can contain anything. But passing machine dependent things such as, reference, pointers, handles...,via winsock doesn't have a meaning, because as soon as it reaches the other machine it becomes obsolete because it will be pointing somewhere else. So in the case of objects, you can pass the object as a whole or pass the data and re-create the data in the client machine (which-ever is OK).
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  3. #3
    Join Date
    Jun 2004
    Posts
    17
    you need to be able to serialize/deserialize your objects, as with mfc's CArchive class.

    xml is a general solution to this problem & quite a few databases will return queries in xml. you can parse them out using a SAX library like apache xerxes.

    you still have to pay attention to the context of yr data, such as timezones, currency, etc. depends how far yr client is from yr server...

  4. #4
    Join Date
    Mar 2000
    Posts
    66
    Yeah, I've done applications using CArchive and CSocket before, but this time I'm going with winsock, and avoiding the MFC classes.

    I've done a little more reading, and I found several posts that say that using strutures is not a good idea due to data alignment issues. Do I need to pack all my data into a formatted char on the client instead (maybe XML), and then just parse it on the server?

  5. #5
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354
    Originally posted by R. Myers
    I've done a little more reading, and I found several posts that say that using strutures is not a good idea due to data alignment issues.
    Not exactly. You can avoid this problem as long as you are pack your structure using the #pragma pack() on both sides. Using structures together with unions provide an easy and efficient way to send information (as a header) about the data that is being passed.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)