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:
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
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