Archived Forum Post

Index of archived forum posts

Question:

Socket with german vowl (äöüß) in C++/MFC

Jul 18 '13 at 10:00

Hello, i started to implement a socket which i do check for received data in a thread. Works as desired, but....i can not get the german vowl (umlauts) to work. I did try socket.put_Utf8(); but with no effective change.I receive crytical letters...


Answer

See this: Socket Programming "Must Know" Concepts

(from the web page at the above URL)

5. Sending and Receiving Strings

Let’s say you want to send the string “ABC” to the connected peer. Most programmers implicitly assume it means sending three bytes: 0×41, 0×42, and 0×43. This is usually correct, but the assumption was made that the communicating programs have pre-agreed upon using the ANSI charset (such as Windows-1252) such that “A” is represented by a single byte having the value 0×41, and “B” is represented by 0×42, etc. What if the sender sends ANSI but the receiver is expecting Unicode (utf-16). The receiver would be expecting 6 bytes because “A” is represented by 2 bytes (0×41, 0×00), “B” is represented by 0×42, 0×00, and so on..

The StringCharset property controls how strings are sent and received. It defaults to “ANSI”. If, for example, it is set to “Unicode”, then a call to SendString(”ABC”) would result in the sending of 6 bytes: 0×41, 0×00, 0×42, 0×00, 0×43, 0×00. The ReceiveString method would know to interpret the incoming bytes as 2-byte/char Unicode chars and correctly return the string “ABC” to the caller.

This is even more crucial when sending non-English characters, where there are many more choices for character encodings. For example, Japanese strings might be sent in Shift_JIS, iso-2022-jp, utf-8, Unicode (ucs-2), euc-jp, etc. It is important that the communicating peers agree on the byte representation of the strings sent and received.


Answer

EDIT:

i tested my winsock.exe which is waiting for a Connection with Telnet and other Clients (e.g. http://www.codeproject.com/Articles/21007/MFC-Telnet-Application). Works good with chars like äöü. I did try to get this to work with chilkat-socket like this

socket.put_Utf8(true);
socket.put_StringCharset("utf-8");

CString val ="cd ölf";

success = socket.SendString(val);

I did send a chcp 1252 as the first command so it Shows correctly in my Editcontrol with Foldername "ölf".

But a "cd ölf" gives:

C:> cd lf

Das System kann den angegebenen Pfad nicht finden.

The System is unable to find the path 'lf' with should have been 'ölf'