ofxTCPServer to send non-English message

I am new to the network add-on. What I am doing is to make a chat room for different languages.
However, I found it strange when sending a string which is set to Chinese, Japanese, etc. The side receiving the message cannot be interpreted. Any clues on that please? Thank you all :pray:

You can use " sendRawBytes( int clientid , const char* , const int numBytes ) " in ofxTCPserver and ofxTCPClient.

First, change to “char*”.
and than Send “char*” to somewhere.
and change “char*” to “string” again when someone’s received.

example

    string korean ="안녕 ~ 오픈프레임웍스 is Hello openframeworks";
    cout << korean.size() << endl;
    char chat_bytes[korean.size()];
    strcpy(chat_bytes,korean.c_str());
    
    
    //may be you use like this.
    //server.sendRawBytes(1 ,send_bytes , korean.size());
    //
    //
    //Let's make virtual situation, state on networks
    //
    //... bytes send to anywhere....
    //... ( after a while) ...
    //... some client receive bytes ...
    
    
    
    //
    // and someone use like this.
    string received = string(chat_bytes);
    
    
    //
    //check for "ok".
    std::cout << received << endl;

I hope this.

Still not working ?

It’s pretty difficult. Isn’t it?
but, best way is encoding “UTF-8” I think.
And you can use " wstring_convert(…) " in c++11. (also openframeworks has it.)

how to use " wstring_convert ".
may be, can find answer from next person.
(:sweat_smile: , sorry, actually I don’t know How use it exactly.)

thank you jjongun, unluckily it is not working, but a good hint from you =)

I wonder if I need to convert my original string to wstring and then send the raw byte to client side and then convert the received wstring to string… let me try ~

try to ofxUnicode

Thank you ZhiJian, but I found the add-on failed to compile, using vs2015 and of 0.9.3. Any thing I did wrong?

嗯,有什么报错提示吗?

dc82 forum@openframeworks.cc于2016年4月4日周一 上午1:51写道:

from ucdn.c:

uint32_t ucdn_mirror(uint32_t code)
{
MirrorPair mp = {0};
MirrorPair *res;

if (get_ucd_record(code)->mirrored == 0)
    return code;

mp.from = code;
res = bsearch(&mp, mirror_pairs, BIDI_MIRROR_LEN, sizeof(MirrorPair),
        compare_mp);

if (res == NULL)
    return code;
else
    return res->to;

}

錯誤 C2440 ‘=’: 無法由 ‘void *’ 轉換為 ‘MirrorPair *’ unicodeTest

等VS2015加载完(大概是30秒左右)后,在右边打开例子的src文件还有addon的src文件,把里面带"-"前缀的都删掉,然后再生成解决方案试试。

dc82 forum@openframeworks.cc于2016年4月4日周一 上午2:59写道:

I try to use the project generator to create a new project with ofxUnicode add-on, right after the first build, an error appears in ucdn.c, its about the function

uint32_t ucdn_mirror(uint32_t code)
{

res = bsearch(&mp, mirror_pairs, BIDI_MIRROR_LEN, sizeof(MirrorPair),
compare_mp);

}

error: cannot convert “void *” to “MirrorPair *”, may I have your advise on this? I tried ZhiJian’s suggestion but cannot find any. Thank you All

I try to convert the std::string to utf8 format before using the ofxTCPServer to send it out, everything is alright now!! Thank you all for your help.

string convert_utf8_str(std::string src_str)
{
int size = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, src_str.c_str(), src_str.length(), nullptr, 0);
std::wstring utf16_str(size, ‘\0’);
MultiByteToWideChar(CP_ACP, MB_COMPOSITE, src_str.c_str(), src_str.length(), &utf16_str[0], size);

size = WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),utf16_str.length(), nullptr, 0,nullptr, nullptr);
std::string utf8_str(size, '\0');
WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),utf16_str.length(), &utf8_str[0], size,nullptr, nullptr);

return utf8_str;

}

2 Likes

oh,man.I knew you can do it ~