M
Martin Greul
Hello together,
I want to copy a integer length in a array.
How can I do that?
I have a solution with unsafe.
http://www1.minpic.de/bild_anzeigen.php?id=79735&key=36633275&ende
But I think is the wrong way.
Maybe somebody can help me.
Thanks.
Greetng Martin
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
unsafe void SendTelegram(string telegramm)
//void SendTelegram(string telegramm)
{
BinaryWriter writer = new BinaryWriter(_stream);
byte[] data = TextEncoding.GetBytes(telegramm);
int lengthInNetworkOrder =
IPAddress.NetworkToHostOrder(data.Length + 4);
int nLength = data.Length;
// ** Specification --> header (4 Byte)
Byte[] bytesSent = new Byte[nLength + 4];
fixed (byte* p = &bytesSent[0])
{
int* pi = (int*)p;
*pi = System.Net.IPAddress.NetworkToHostOrder(nLength + 4);
}
System.Array.Copy(data, 0, bytesSent, 4, nLength);
// writer.Write(lengthInNetworkOrder);
writer.Write(bytesSent);
}
I want to copy a integer length in a array.
How can I do that?
I have a solution with unsafe.
http://www1.minpic.de/bild_anzeigen.php?id=79735&key=36633275&ende
But I think is the wrong way.
Maybe somebody can help me.
Thanks.
Greetng Martin
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
unsafe void SendTelegram(string telegramm)
//void SendTelegram(string telegramm)
{
BinaryWriter writer = new BinaryWriter(_stream);
byte[] data = TextEncoding.GetBytes(telegramm);
int lengthInNetworkOrder =
IPAddress.NetworkToHostOrder(data.Length + 4);
int nLength = data.Length;
// ** Specification --> header (4 Byte)
Byte[] bytesSent = new Byte[nLength + 4];
fixed (byte* p = &bytesSent[0])
{
int* pi = (int*)p;
*pi = System.Net.IPAddress.NetworkToHostOrder(nLength + 4);
}
System.Array.Copy(data, 0, bytesSent, 4, nLength);
// writer.Write(lengthInNetworkOrder);
writer.Write(bytesSent);
}