Salut
Dans le cadre de mon projet je doit transmettre des données via des sockets. Pour cela on m'a conseillé d'utiliser la serialisation des données.
j'utilise la bibliothèque Boost.
Tout marche bien au niveau du serveur mes données sont envoyées, mais niveau du client j'ai une erreur.
Voici mon code:
Serveur :
Client:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 #include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> class Note { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & numerateur; ar & denominateur; } int numerateur; int denominateur; public: Note() {}; Note(int n, int d) : numerateur(n), denominateur(d) {} }; int main() { ...... std::ofstream ofs("fichierDeSerialisation"); const Note maNoteDePhysisque(20,20); { boost::archive::text_oarchive oa(ofs); oa << maNoteDePhysisque; // envoi de la structure sock_err = send(Client,(char *)&oa, sizeof(oa), 0); ...... }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> class Note { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & numerateur; ar & denominateur; } int numerateur; int denominateur; public: Note() {}; Note(int n, int d) : numerateur(n), denominateur(d) {} }; int main() { ...... Note monAncienneNote; { /* Si l'on reçoit des informations : on les affiche à l'écran */ recv(ClientSock,(char *)&monAncienneNote, sizeof(monAncienneNote), 0); std::ifstream ofs("fichierDeSerialisation"); boost::archive::text_iarchive ia(ofs); ia >> monAncienneNote; ....... }
Erreur :
Exception non gérée à 0x7c812aeb dans SOCKET_CLIENT.exe : Exception Microsoft C++ : boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::archive::archive_exception> > à l'emplacement mémoire 0x0012f7a0..
Merci pour votre aide.
Partager