Click here to Skip to main content
15,888,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
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,
Dave
Posted
Comments
Sergey Alexandrovich Kryukov 31-Oct-11 18:00pm    
Do you mean C++, not C++/CLI?
--SA

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.
Like:
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
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 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.
--SA
Espen Harlinn 31-Oct-11 18:42pm    
OP specified that the server could not be modified
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 (http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29[^]). 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 (http://en.wikipedia.org/wiki/Interface_description_language[^]) 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 (http://en.wikipedia.org/wiki/SOAP[^]) or JSON (http://en.wikipedia.org/wiki/JSON[^]).

Here you can find assortment of product implementing JSON for different platforms and languages: http://www.json.org/[^].

Good luck,
—SA
 
Share this answer
 
Comments
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 ...
http://www.antlr.org/grammar/list
Sergey Alexandrovich Kryukov 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.
--SA
Espen Harlinn 31-Oct-11 20:14pm    
http://iiop-net.sourceforge.net/ 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 :)
Sergey Alexandrovich Kryukov 1-Nov-11 0:05am    
I knew you would tell me about it. :-)
Good to know, thank you for sharing.
--SA
Sergey Alexandrovich Kryukov 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?
--SA
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.

Dave
 
Share this answer
 
Don't understand the question.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900