Solved

Serialization of chat message.

Posted on 2010-09-10
6
319 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 39

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 39

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 39

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

760 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

21 Experts available now in Live!

Get 1:1 Help Now