I want to create a data packet and write it to socket.
This packet starts with 'C0' hex value.
In php I easily can create it with this code:
$a = "\xC0";
now I want to create it in c#. How can do this?
I want to create a data packet and write it to socket.
This packet starts with 'C0' hex value.
In php I easily can create it with this code:
$a = "\xC0";
now I want to create it in c#. How can do this?
In C#, strings are Unicode-encoded, so you shouldn't use them for binary data. Instead use a byte array.
To create a byte array starting with C0, do something like this:
byte[] packet = new byte[] { 0xC0, /* Other values */ };
If you have an existing string that you want to send, you can use Encoding.ASCII to convert it to the bytes you need.
If you are sending bytes it's as easy as:
byte a = 0xC0;
If the packet contains text, you can start a string:
string a = "\xC0";
For more information on String Literals: http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx