Networking in Cocoa
Subject:   Problems with mot exessage handling
Date:   2003-05-30 00:14:50
From:   anonymous2
Response to: Problems with mot exessage handling

the second problem is caused by the [message length] statement in sendMessage method is return the character's number by Unicode encoding.

For example, if you have a string contains 1 chinese character, [message length] will return 1; but this string might be 4 bytes long.

our dataWithBytes:length method of NSData need the real length of the string in bytes. So, this results in sending the string imcompletely.

what we should do is use the strlen of C instead:

NSData *message=[[NSData dataWithBytes:[message UTF8String] length: strlen([message UTF8String])];