CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    14

    Sending data over SOCKETS (serialization)

    Hi,

    I am trying to send an array of objects over a socket using winsock. Obviously I can't send the array in its current form and need to somehow convert it to an appropriate format. I have heard of the following "ideas" - serialisation, and converting to a byte array.

    Would anyone be able to give me a quick example of how I might approach this, considering that the array we wish to convert is an array called products of type ProductInfo:

    ProductInfo products[10];


    I will be sending the eventual data via: send(client, senddata, (int)strlen(senddata), 0 );

    David.

  2. #2
    Join Date
    Feb 2009
    Posts
    14

    Re: Sending data over SOCKETS (serialization)

    Came across the following stuff, which does work, but I want the character representation, not the file. Is there something similar???

    ofstream out("binary.txt", ios::binary);
    out.write((char*)&products, sizeof(products));
    out.close();

    ProductInfo test[10];

    ifstream in("binary.txt", ios::binary);
    in.read((char*)&test, sizeof(test));
    cout << test[2].get_make();

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured