Socket Communications between C++ and C#
-
I'm having a very difficult time figuring out what should be a simple problem. I have a server application developed using C++ (on Linux, so it's not being ported to C# any time soon) that sends and receives standard structures over a socket. How can I read those structures, interpret them as attributes, and send a sensible reply? :confused: I've been experimenting with serializing classes with a binary formatter, accessing raw memory, and just creating a plain structure, but could find no way to send the bytes through the socket... Thanks for your help, Jason
-
I'm having a very difficult time figuring out what should be a simple problem. I have a server application developed using C++ (on Linux, so it's not being ported to C# any time soon) that sends and receives standard structures over a socket. How can I read those structures, interpret them as attributes, and send a sensible reply? :confused: I've been experimenting with serializing classes with a binary formatter, accessing raw memory, and just creating a plain structure, but could find no way to send the bytes through the socket... Thanks for your help, Jason
When you serialize a class extra data is written to tell the runtime what type of object is being serialized. I have no idea if MS put this functionality in but you can look to see if you can work something up between the StructLayout attribute (normally set to Sequential) and the MarshalAs attribute. Then try getting a byte[] array with that data. I just thought of a hack that might work; create a struct, with the first and last elements being an int containing magic numbers; serialize the data to a MemoryStream, then retrieve the bytes from it, using only the data between your magic numbers to send across the wire. Like I said its a hack, and its entirely dependent on how the binary formatter serializes data (assuming it serializes the data in the same order it is in your struct). James Sonork ID: 100.11138 - Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971