Why can't I transfer non-english letters over my network connectio

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

Guest

I'm using the following to transfer the content of two strings containing
non-english letters

byte[] responseB = Encoding.ASCII.GetBytes(responseHdr.ToString() +
responseBody.ToString());

But when I receive it, the non-english letters have been replaced by
question marks (?). What could be wrong?

I receive using

clientSocket.BeginReceive(info.buffer, 0, info.buffer.Length, 0, new
AsyncCallback(this.OnReceiveResults), info);

private void OnReceiveResults(IAsyncResult info)
{
//Display the results in the list box
InfoCarrier info_carrier = (InfoCarrier) info.AsyncState;
if (info_carrier.Request_Status == InfoCarrier.mc_ReqStatusOK)
{
m_Lbl_Status.Text = "The results have been successfully fetched.";
listBoxResults.Items.Clear();

const int NOT_FOUND = -1;
int currPos = 0;
int hasNext = info_carrier.Body.IndexOf('\n');
while (hasNext != NOT_FOUND)
{
listBoxResults.Items.Add(info_carrier.Body.Substring(currPos, hasNext -
currPos).Replace('|', '\t'));
currPos = hasNext;
hasNext = info_carrier.Body.IndexOf('\n', hasNext + 1);
}
}
}

In the listbox there are only ?:s instead of the non-english letters.
 
Joachim said:
I'm using the following to transfer the content of two strings containing
non-english letters

byte[] responseB = Encoding.ASCII.GetBytes(responseHdr.ToString() +
responseBody.ToString());

Well that's the problem then. ASCII doesn't contain any non-English
letters. I suggest you use a different encoding, such as UTF-8.
 
Hey,

I had that problem when I tried to send/receive Russian letters
over the TCP...

Use:
<code>
byte[] msg=System.Text.Encoding.UTF8.GetBytes(message)
</code>

to send; and the following to receive:
You might as well just use a different encoding...
These days I prefer UTF8, but several years ago, when Windows 98/Me
were still out there (not that they aren't now) and unicode wasn't
as popular, as it is now, I would use Windows-1251 (Cyrillic) or
give a user a choice.

<code>
string message=
System.Text.Encoding.UTF8.GetString(bytes).Replace(
((char)0).ToString(), "");
</code>
The replace part is to remove all 'null' characters from the stream,
since I am receiving a chunk of 256 bytes at a time, and if the message
is shorter, the rest consists of '\0' characters.

I'm using the following to transfer the content of two strings containing
non-english letters

byte[] responseB = Encoding.ASCII.GetBytes(responseHdr.ToString() +
responseBody.ToString());

But when I receive it, the non-english letters have been replaced by
question marks (?). What could be wrong?

I receive using

clientSocket.BeginReceive(info.buffer, 0, info.buffer.Length, 0, new
AsyncCallback(this.OnReceiveResults), info);

private void OnReceiveResults(IAsyncResult info)
{
//Display the results in the list box
InfoCarrier info_carrier = (InfoCarrier) info.AsyncState;
if (info_carrier.Request_Status == InfoCarrier.mc_ReqStatusOK)
{
m_Lbl_Status.Text = "The results have been successfully fetched.";
listBoxResults.Items.Clear();

const int NOT_FOUND = -1;
int currPos = 0;
int hasNext = info_carrier.Body.IndexOf('\n');
while (hasNext != NOT_FOUND)
{
listBoxResults.Items.Add(info_carrier.Body.Substring(currPos, hasNext -
currPos).Replace('|', '\t'));
currPos = hasNext;
hasNext = info_carrier.Body.IndexOf('\n', hasNext + 1);
}
}
}

In the listbox there are only ?:s instead of the non-english letters.



--
Regards,
Nurchi BECHED

P.S.
C makes it easy to shoot yourself in the foot;
C++ makes it harder, but when you do,
it blows away your whole leg."
--Bjarne Stroustrup
 
Back
Top