Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Serialization of chat message.

Posted on 2010-09-10
6
Medium Priority
?
333 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 41

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 41

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 1000 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 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

610 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