|
-
May 7th, 2009, 11:30 AM
#1
[RESOLVED] Text encoding issues, I think.
Hey.
I am working on a project where my task is to expand an existing library with a couple of new features. It revolves around networking, sending and receiving data.
The "core" of this library handles all network communication, and it actually works with the data being sent and received as strings (ugh!), even though they might not represent strings.
So I have been working on it for about 2 weeks now and it have gone surprisingly well, until just recently.
The problem:
I am receiving 4 bytes from a remote host, I must then send these 4 bytes back to the host. The method that handles the sending accepts strings only, so I'll have to build a string out of the 4 bytes like so:
Code:
MyString = String.Empty
For i As Integer = 5 To 8
MyString &= Char.ConvertFromUtf32(Response(i))
Next
(Where Response is a byte array).
I then send this string to the 'sending method' in the library, which turns the string back into a byte array like so:
Code:
_sendBuffer = System.Text.Encoding.[Default].GetBytes(request)
Now in theory the 4 bytes I received and the 4 bytes that _sendBuffer contains should be the same. This is not always the case. Most of the time it is, but on some occasions one or more bytes have different values.
I have tried changing the encoding on the GetBytes call, but to avail.
I feel like this post doesn't make a bit of sense now but hopefully it does. Please ask if theres something unclear.
Edit: Perhaps I should include an example where it fails.
Received bytes:
192, 148, 253, 9
Bytes returned after converting them to a string and then back again:
192, 63, 253, 9
So, 148 is suddenly turned into 63 for some reason.
I really need help with this.
Last edited by Atheist; May 7th, 2009 at 11:34 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|