Click here to Skip to main content
13,456,800 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am new to C# and .NET in general (ex-Borland C/C++ programmer). I have been given a task to collect and display data from a server program that was written in C/C++. I cannot make changes to the server code, but I have the Interface Control Document for it.

The server requires several initialization messages to be sent before it will pass the data back. Then the data will be streamed real-time (near real-time) to the client. Speed of messages can be as fast as the microsecond level. The server receives and passes data as structures. All data (in both directions) have two header fields: messageId, and messageSize.

My questions are:
1. How do I send class/struct data to the server (not too sure about serialization, yet)?
2. Will the server decode a serialized message properly?
3. Will the client be able to decode the data sent from the server?

I know this is a lot to answer, but I have searched the web for days and have only gotten more confused about serialization (there seems to be so many different ways to do it).

Any help would be immensely appreciated,
Posted 31-Oct-11 11:38am
SAKryukov 31-Oct-11 18:00pm
Do you mean C++, not C++/CLI?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I think you need to look at BinaryReader Class[^]
and BinaryWriter Class[^]

I cannot make changes to the server code
Use the above classes to serialize/deserialize the messages according to the format dictated by the server.
You need to determine how many bytes are used for each field, and then decode the message field by field.
messageId - 4 bytes, int
messageSize - 2 bytes, ushort
timeStamp - 8 bytes, double
quality - 1 byte, sbyte
value - 8 bytes, double

Strings will most likely need special handling as the BinaryReader and BinaryWriter defaults to unicode strings prefixed by a 7-bit encoded integer[^] specifying the length of the string. You need to know about the Encoding Class[^]

Or if you allready have a C++ client use C++/CLI or implement a COM wrapper using C++ builder. The last one is probably the easiest way to do it.

Best regards
Espen Harlinn
SAKryukov 31-Oct-11 18:18pm
Not sure. How can you guarantee that C# code will write what C++ code will read? How to create identical (from the persistence standpoint) classes in different system? At least you should explain it. Will you look at my solution -- I have some ideas.
Espen Harlinn 31-Oct-11 18:42pm
OP specified that the server could not be modified
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Please see my comment to the question. A will assume you mean .NET vs. C++, not C++/CLI. If both sides are .NET, there are no problems whatsoever. All code and serialization mechanism are platform-wide in .NET, they are not specific to language. Also, in .NET serialization is fundamentally based on Reflection ([^]). So, how about interoperability between .NET and "classic" C++.

Well, possible, but in practice very boring stuff, at least these days.

Basically, you need to create logically identical classes in both systems and use identical means of serialization. There can be several boring approaches. First, you can develop such classes or translate from language to language manually. Also, you can develop interfaces for classes using IDL ([^]) and generate code for both .NET and C++. On top of it, you can use serialization in both system using some common standard. You can try Soap ([^]) or JSON ([^]).

Here you can find assortment of product implementing JSON for different platforms and languages:[^].

Good luck,
Espen Harlinn 31-Oct-11 18:45pm
5'ed - looking at idl is a good idea, antlr has an Corba idl grammar that could be used - for a complicated protocol this would make sense ...
SAKryukov 31-Oct-11 18:56pm
Oh, yes, and Corba (how about Corba for .NET? It could be found somewhere...) -- a good point.
Thank you, Espen.
Espen Harlinn 31-Oct-11 20:14pm works fairly well, haven't used it for a couple of years, but noticed that it was last updated 2011-09-24, so it's still alive :)
SAKryukov 1-Nov-11 0:05am
I knew you would tell me about it. :-)
Good to know, thank you for sharing.
SAKryukov 1-Nov-11 0:07am
By the way, this product could present one of the most direct solutions to OP's problem, don't you think so?
Espen Harlinn 1-Nov-11 6:06am
It would provide for a good solution, but he can't modify the server ...
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Sorry this took so long. I got pulled off the project for another and completely forgot about the question.

It turns out that I was doing it right, but they (the developers of the other program) changed their code and didn't tell me until I got back on the project. So thanks for the comments, anyway.

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Don't understand the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180322.1 | Last Updated 9 Aug 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100