Click here to Skip to main content
15,892,737 members
Home / Discussions / C#
   

C#

 
GeneralSocket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot22-Mar-04 10:25
goodpilot22-Mar-04 10:25 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Corinna John22-Mar-04 19:48
Corinna John22-Mar-04 19:48 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart23-Mar-04 3:18
protectorHeath Stewart23-Mar-04 3:18 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot23-Mar-04 4:42
goodpilot23-Mar-04 4:42 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart23-Mar-04 5:20
protectorHeath Stewart23-Mar-04 5:20 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot23-Mar-04 5:28
goodpilot23-Mar-04 5:28 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot24-Mar-04 3:56
goodpilot24-Mar-04 3:56 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot24-Mar-04 3:59
goodpilot24-Mar-04 3:59 
I have tried this successfully. But only with a class and struct that does not contain a string or byte array field. For example:

[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct MyPacket
{
public MyPacket(DateTime dateTime, int line, int msgLen)
{
dt = DateTime.Now;
iLine = 0;
iMsgLen = 0;
msg = new byte[80];
}

public DateTime dt;
public int iLine;
public int iMsgLen;
public byte[] msg;
}

Marshal.Sizeof(MyPacket) returns 20. So when it is sent over the network I the contents of msg is lost. Obviously because byte[] is a reference to an array.

So, now the question is how can I pass classes or structures as binary data if they contain arrays, for example a message that contains a stock quote needs to include a symbol name (i.e. "MSFT").

Can you help me out with this as well? I have not been able to find any examples or documentation that shows StructLayout being used with structures or classes that contain strings or arrays.

By the way, what does Microsoft MVP mean? Are you a Most Valuable Player at Microsoft?

Thanks for the assistance,

Robert G. Ellis

GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart24-Mar-04 4:13
protectorHeath Stewart24-Mar-04 4:13 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot24-Mar-04 16:46
goodpilot24-Mar-04 16:46 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Sascha Andres23-Mar-04 3:17
Sascha Andres23-Mar-04 3:17 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart23-Mar-04 3:20
protectorHeath Stewart23-Mar-04 3:20 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Sascha Andres23-Mar-04 3:34
Sascha Andres23-Mar-04 3:34 
QuestionHow do I check wether a url/file exists Pin
kris.mackintosh22-Mar-04 10:17
kris.mackintosh22-Mar-04 10:17 
AnswerRe: How do I check wether a url/file exists Pin
Heath Stewart22-Mar-04 11:56
protectorHeath Stewart22-Mar-04 11:56 
Generalfrom VC6 dll Pin
yyf22-Mar-04 10:10
yyf22-Mar-04 10:10 
GeneralRe: from VC6 dll Pin
Heath Stewart22-Mar-04 11:47
protectorHeath Stewart22-Mar-04 11:47 
GeneralRe: from VC6 dll Pin
yyf23-Mar-04 3:10
yyf23-Mar-04 3:10 
GeneralRe: from VC6 dll Pin
Heath Stewart23-Mar-04 3:13
protectorHeath Stewart23-Mar-04 3:13 
GeneralRe: from VC6 dll Pin
yyf23-Mar-04 4:01
yyf23-Mar-04 4:01 
GeneralLoop through a Datagrid Pin
Anonymous22-Mar-04 9:55
Anonymous22-Mar-04 9:55 
GeneralRe: Loop through a Datagrid Pin
Heath Stewart22-Mar-04 11:46
protectorHeath Stewart22-Mar-04 11:46 
GeneralRe: Loop through a Datagrid Pin
Anonymous22-Mar-04 11:51
Anonymous22-Mar-04 11:51 
GeneralRe: Loop through a Datagrid Pin
Heath Stewart22-Mar-04 11:57
protectorHeath Stewart22-Mar-04 11:57 
GeneralRe: Loop through a Datagrid Pin
Ruchi Gupta22-Mar-04 12:11
Ruchi Gupta22-Mar-04 12:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.