473,412 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

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

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.Substri ng(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.
Nov 17 '05 #1
2 1282
Joachim <Jo*****@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
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.

On Mon, 28 Mar 2005 20:49:02 -0800, Joachim
<Jo*****@discussions.microsoft.com> wrote:
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.Substri ng(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
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
15
by: dee | last post by:
Hi, I'm curious why MS decided to have Transfer hide the target page's url invisible? Any guesses ? Thanks. Dee.
7
by: monkeydragon | last post by:
how to would you transfer a DWORD variable from inside of a function to the caller ex. InvokeProcessData(LPDWORD prtDW) { ... // we have created, initialized and processed // dword variable...
1
by: Chris | last post by:
I am thinking of creating a custom 404 page which does a server.transfer to a variety of different pages. My question is what shows up in the log, which the web statistics are based on? 1. The non...
11
pbmods
by: pbmods | last post by:
A somewhat obscure hack has emerged recently that is an offshoot of the now-infamous XSS. It is known as Cross-Site Request Forgery, or XSRF for short. XSRF is a form of temporary identity theft...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.