Structures question.

G

Guest

Hi,

I'm deveoping a Client/Server application.
I want to send information by using structures.
I want to have a standard header structure, and variable lenght
data.
for example,
---------------------------------------
public struct Header
{
public int sequenceNumber;
public int serviceRequest ;
----
----
}

public struct Info
{
Header head;
byte[] data;
}
-------------------------------
How do we marshal "Info" structure with variable byte[] data.
Currently I'm marshalling in the following way,

[MarshalAs( UnmanagedType.ByValArray, SizeConst= 1024)]
byte[] data;

but as the data should be of variable length, how can we marshal the byte[]
without specifying the size of the byte[]. I mean is there any way that we
can
find the size of the byte[] just before marshalling the sturcture "Info".

Kindly let me know,

Cheers,

Naveen.
 
G

Guest

Honestly speaking, I don't know how to use Dataset structures and sending them
over as XML. Could you explain in some detail please.

Actually, I'm developing a Class library(Dll) that helps Client/Server
applications.
 
C

Chad Z. Hower aka Kudzu

=?Utf-8?B?TmF2ZWVuIE11a2tlbGxp?=
Honestly speaking, I don't know how to use Dataset structures and
sending them over as XML. Could you explain in some detail please.

A good way is to create a typed dataset. Try this article, its not exactly
what you need, but I think you'll quickly get the idea of how it applies to
your situation. Datatables also supports multiple rows altough this article
does not demonstrate this.

http://www.codeproject.com/dotnet/XMLSettingsFile.asp


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 
S

sadhu

If all you're trying is to send instances of objects over the wire, why
not serialize them and send them directly, instead of trying to marshal
yourself?

MemoryStream ms = new MemoryStream();
BinaryFormatter f = new BinaryFormatter();

f.Serialize(yourObject, ms);

byte []data = ms.ToArray();
socket.Write(data);

You can then do the reverse on the receiving side.

Regards
Senthil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top