Error coding! Emergency! Help~~

Guys,i wanna make a client using c/c++ to comunicate with server in XML statement. When my client send a chinese character string to the server, the server can’'t receive correctly.Here is the simple test code in my client bellow:

#define MESSAGE //for simple example

setlocale(LC_ALL, “utf-8”);

char send_mess[200];

char temp[20];

WCHAR test[20] = L"XX123"; //XX stands for two chinese characters

wcstombs(input, test, 20);

sprintf(send_mess,MESSAGE, temp);

//my function SenddMessage send XML statement using socket and send()

SendMessage(login_mes,connfd); //connfd is my socket

server receive:


When setlocale(LC_ALL, “.936”);

server receive:


Please help me ! Tell me how to send Chinese character(unicode) correctly! Emergency!Thank you all~~

Hi Lijun,

your client should send (and looking at your code it seems it is sending) an UTF-8 XML and not an UCS-2 or UCS-4 unicode message. Could you print the message to a file and check that it is valid UTF-8?


to LG:

my problem was solved, thank you!

I also meet this problem,and when I use chinese username, login failed. could you tell me how to solve it? seems to be the thread to work on as it is also yours.

thank you very much