?
Solved

Serialization of chat message.

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

762 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