Solved

Serialization of chat message.

Posted on 2010-09-10
6
325 Views
Last Modified: 2012-05-10
Hey Experts.
I'm building a client/server chat program (I'm pretty sure some you guys may have seen some of my code around here, I've been asking a lot of questions about this... heh.) and everything is done with the server and client components that I've planned.

What is left is the serialization of the messages sent by the client to the server.
Can you guys point me to a way to do this in a text format?
I don't want to add any libraries to my program, need to do this with the standard libraries in C++. I have planned to do this with a class that has a Pack( ) and Unpack( ) functions, but I don't know how to begin with this. The serialization has to be something like this: [time] [username] [msg].

The way things will work is like this: before sending the message through the socket, the program will pack the message and send it, then on the server side the packed message will be received, unpacked and stored in a container.

Any thoughts?
Thanks in advance.
0
Comment
Question by:PDamasceno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 33648855
http://ubuntuforums.org/showthread.php?t=687947

Though it's ubuntu the discussion is correct IMO.  You first want to pass the length of the string you're sending, then process the string behind it.

For a class pass in your socket and let the class do the work.

eg:

class Message
{
  //datamembers not included

  Message();

  public:
     bool Send(socket mySocket);  // returns true if all goes well, false if there's an error.
                                    // other methods.
}

0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 33648882
0
 

Author Comment

by:PDamasceno
ID: 33648956
My problem is not with the sending throw socket mechanics.
Maybe I wasn't that clear.
I need a way to serialize the message typed by the client, send it through the socket and when the message is received, deserialize it and store in the serve message list.

The socket mechanisms in my program are all working fine.
I just don't know how to start this serialize thing. Like I said in the question post, it has to be in text format and need to have this format: [time] [username] [message]
The time part I can make the Pack( ) function set that, the username I can get it from the Client class and the message I can get from another class that handles the job of sending messages to the server. After I get all these data, it will be all packed together.

Hope I was more clear now.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PDamasceno
ID: 33648969
*My problem is not with the sending THROUGH socket mechanics.
0
 
LVL 32

Accepted Solution

by:
phoffric earned 250 total points
ID: 33649428
Here is a FAQ on serialization that may be of interest to you:
     http://www.parashift.com/c++-faq-lite/serialization.html
0
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
ID: 33649865
so create a method pack which pulls the info then send it through the socket.

http://www.functionx.com/cpp/articles/serialization.htm

Writing to a file is no different than writing to a socket (except you can't seek).  So essentailly just write out the info in order that you want it.

then on the receiving end read it back in the order.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question