Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# TCP/IP .NET4
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 31-Oct-11 11:38am
cdavel366
Comments
SAKryukov at 31-Oct-11 18:00pm
   
Do you mean C++, not C++/CLI?
--SA
Rate this: bad
good
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.
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
  Permalink  
v3
Comments
SAKryukov at 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 at 31-Oct-11 18:42pm
   
OP specified that the server could not be modified
Rate this: bad
good
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 (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
  Permalink  
Comments
Espen Harlinn at 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
SAKryukov at 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 at 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 :)
SAKryukov at 1-Nov-11 0:05am
   
I knew you would tell me about it. :-)
Good to know, thank you for sharing.
--SA
SAKryukov at 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
Espen Harlinn at 1-Nov-11 6:06am
   
It would provide for a good solution, but he can't modify the server ...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Don't understand the question.
  Permalink  
Rate this: bad
good
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.
 
Dave
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 345
2 CPallini 200
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,028
2 CPallini 4,700
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 9 Aug 2012
Copyright © CodeProject, 1999-2014
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