Socket - send bytes to 255

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using sockets. I need to send bytes without alternation from 0-255. When
I use the standard,

Byte[] bytestuff = System.Text.Encoding.ASCII.GetBytes(stuff.ToCharArray());
tSocket.Send(bytestuff,bytestuff.Length,0);

It encodes most characters to ? past asci 127. I beleive that's because of
the Encoding,ASCII. How can I send info preserving the raw bits for asci
128-255?

Thanks in advance.
 
Dave said:
I'm using sockets. I need to send bytes without alternation from 0-255. When
I use the standard,

Byte[] bytestuff = System.Text.Encoding.ASCII.GetBytes(stuff.ToCharArray());
tSocket.Send(bytestuff,bytestuff.Length,0);

It encodes most characters to ? past asci 127. I beleive that's because of
the Encoding,ASCII. How can I send info preserving the raw bits for asci
128-255?

Use the System.Text.Encoding.UTF8 object. Also, you don't need to
convert the string to a char[], as GetBytes() will take either type.
 
Hi,

It's the Encoding, try UTF8 instead

now, if you are sending it to a socket stream you have to make sure that
both ends work the same.

Cheers,
 
Dave said:
I'm using sockets. I need to send bytes without alternation from 0-255. When
I use the standard,

Byte[] bytestuff = System.Text.Encoding.ASCII.GetBytes(stuff.ToCharArray());
tSocket.Send(bytestuff,bytestuff.Length,0);

It encodes most characters to ? past asci 127. I beleive that's because of
the Encoding,ASCII. How can I send info preserving the raw bits for asci
128-255?

There are no ASCII characters beyond 127.

If you want to send bytes without alteration, you shouldn't be
converting them into text to start with.

See http://www.pobox.com/~skeet/csharp/unicode.html
 
Back
Top