Sending buffers via sockets

  • Thread starter Thread starter Mik42
  • Start date Start date
M

Mik42

Hello, I'm a newbie in C#, and I hope, that my question is not
overstupid.

I'm writing application that have to send (and receive) data via
TCP/IP. The other side of my socket is VxWorks based application with
no knowledge of .NET Framework. The code that I used in C++ is look
something like this:
-------------------------------------------------
typedef enum {CODE1, CODE2} OP_CODE;
typedef struct
{
OP_CODE op_code;
int iParam
}MSG_ST;

.....
MSG_ST msg;
msg.op_code = CODE1;
msg.iParam = 1;

byte * pBuffer = new byte [sizeof(msg)]
memcpy (pBuffer, &msg, sizeof(msg));
pMySocket->Send(pBuffer... BLA-BLA-BLA...
----------------------------------------------

How can I implement such thing in C#? I know how to open TcpClient,
make GetStream() and byte [] mybuffer to it, but how can I build this
buffer from enums, integers and structs??? And how can I copy short []
to byte []???

Thank you in advance
Mik42
 
Back
Top