send stl vector by a socket

Discussion in 'C Programming' started by pattousai, Dec 7, 2008.

  1. pattousai

    pattousai

    Joined:
    Dec 7, 2008
    Messages:
    1
    Hi everybody!

    I'm a relative newbie in programming, and i have to make an client/server application. So... this application comunicate by a couple of sockets. In the implementation, i found me in a situation that i need to send an stl vector (because in the server size, this array is extremaly variable, and that is why i declare it a stl vector) to the cliente. But i have try some codes and always end in a segmentation fault.

    So... is there a way that i can send an stl vector??

    Well... i will post a demonstration of my problem:
    Code:
    client:
       vector<int> a;
       a.push_back(2);
       a.push_back(10);
       a.push_back(11);
       
       result = write( sockfd, &a, sizeof(a) );
       cout << result << "\n";
    
    Code:
    server:
       vector<int> *a = new vector<int>;
       
       result = read( client_sockfd, &a, sizeof(*a) );
       cout << result << "\n";
       cout << a->back() << "\n";
    
    i already try many variations of these codes (made all vector pointers, cast to void* and etc), and none seen to work.

    the funny thing is that value of result is 12 (in both sides), so... the length is ok. other thing is when i comment the line 'cout << a->back()', the program doesn't abort.

    well, thanks very much to everyone
    pattousai, Dec 7, 2008
    #1
    1. Advertising

  2. pattousai

    dgamez

    Joined:
    Jul 30, 2010
    Messages:
    1
    Hi pattousai,

    Did you find any solution for this ???
    dgamez, Jul 30, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Allerdyce.John@gmail.com
    Replies:
    8
    Views:
    1,912
    Csaba
    Feb 18, 2006
  2. Chris Reay

    Does Socket.send send all bytes?

    Chris Reay, Nov 3, 2003, in forum: Ruby
    Replies:
    2
    Views:
    217
    Chris Reay
    Nov 4, 2003
  3. Ryan Parmeter
    Replies:
    4
    Views:
    242
    Douglas Wells
    Sep 5, 2007
  4. Thomas Rachel
    Replies:
    0
    Views:
    195
    Thomas Rachel
    Jan 7, 2013
  5. Luca Risolia

    STL map to STL vector

    Luca Risolia, Jan 13, 2014, in forum: C++
    Replies:
    32
    Views:
    360
    Seungbeom Kim
    Jan 18, 2014
Loading...

Share This Page