# Socket 통신
Windows 프로그램과 소켓통신을 할 때, 윈PC에서 보내준 한글이 제대로 인식되지 않을때가 발생되어
다음과 같이 해결.
Byte buf[bufferSize];
int nReceivedData = read(clientSd, buf, sizeof(buf));
NSData *bufData = [NSData dataWithByte:buf];
NSString *strData = [[NSString alloc] initWithData:bufData encodign:NSUTF8Encoding];
NSLog(@"strData value : %@", strData); // 한글 잘 나옴.
[strData release];
# QuotedPrintable decode 시 한글 문제.
//-----------------------------------------------
//----------------- C style -------------------
//-----------------------------------------------
static int hex2int( char x )
{
return (x >= '0' && x <= '9') ? x - '0' :
(x >= 'A' && x <= 'F') ? x - 'A' + 10 :
(x >= 'a' && x <= 'f') ? x - 'a' + 10 :
0;
}
- (char *)qp_decode:(const char *)qp
{
const char *in;
char *ret = new char[strlen(qp)+1];
char *out = ret;
for (in = qp; *in; in++ ) {
// Handle encoded chars
if ( *in == '=' ) {
if (in[1] && in[2] ) {
// The sequence is complete, check it
in++; // skip the '='
if (in[0] == '\r' && in[1] == '\n') {
// soft line break, ignore it
in ++;
continue;
}
else if ( isxdigit(in[0]) && isxdigit(in[1]) ) {
// Ok, we have two hex digit: decode them
*out = (hex2int(in[0]) << 4) | hex2int(in[1]);
out++;
in ++;
continue;
}
}
// In all wrong cases leave the original bytes
// (see RFC 2045). They can be incomplete sequence,
// or a '=' followed by non hex digit.
}
// TODO:
// RFC 2045 says to exclude control characters mistakenly
// present (unencoded) in the encoded stream.
// Copy other characters
*out = *in;
out++;
}
*out = 0;
return ret;
}
//-------------------------------------------------------------
NSString *temp = (NSString*)CFStringCreateWithCString(NULL, [qt qp_decode:[[TBXML textForElement:serverDetail] UTF8String]], kCFStringEncodingUTF8);