Solved

Serialization of chat message.

Posted on 2010-09-10
6
322 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now