views:

226

answers:

2

Hi,

i am using vb.net and i would to send some structs to a C++ tcp server.

The problem is the structs i am sending might contain other structs.

Struct{ uint length; byte really; customStruct customStuff; }FirstStruct;

Struct{ uint length; char[] name; }CustomStruct;

Lets say i want to send FirstStruct over to the C++ Server. How do i go about doing it? Some code examples will be great.

thanks.

+4  A: 

Structs can't be sent over sockets, only bytes. You must decide how to convert the structures to a byte stream in the sender, and back to equivalent data structures in the receiver.

Assuming both sides are running Windows*, you can use .NET binary serialization to handle the details. I doubt that supports converting from a VB.NET struct directly to a C struct, but it should be able to construct a reasonable approximation on the receiving end.

* Mono, AFAIK, does not support .NET extensions to C++.

John Millikin
yup. i understand that i need to convert the struct to byte array before sending. The problem i am having is finding examples of doing it and also examples on how to convert a structure that contains members which is of another structure type to byte array.
A: 

I would serialize my vb structs into something like XML ( or JSON ) and parse them on the server side...

SadSido
That is an existing server we are trying to connect to so changing the way it works on the data is impossible :(