null的ascii:<00> 一个ascii占一个字节
未理解
+ (int) nbyte2Int: (NSData *)nd
{
//NSLog(@"[nbyte2Int] nd= %@", [NSString stringWithFormat:@"%@", nd]);
// 测试:假设是00cc
NSString *nstr = [[NSString stringWithFormat:@"%@", nd] substringWithRange:NSMakeRange(1, 4)];
//NSLog(@"[nbyte2Int] str= %@", nstr);
//========================= byte[] --> int =========================
int len = [nstr length];
int hc = 0;
int int_ch = 0, z;
for(int k=0; k<len; k++){
hc = [nstr characterAtIndex:k];
//NSLog(@"[nbyte2Int] hc= %d", hc);
z = (len-1==k) ? 1 : (len-1-k)*16;
if(hc >= '0' && hc <='9') { // 因为字符串'0'是十进制的48,
int_ch += (hc-48)*z;
NSLog(@"hc >= '0' && hc <='9'%c",hc);
}else if(hc >= 'A' && hc <='F') { // 将 'A'~'F'的字符转化为10-15
int_ch += (hc-55)*z;
NSLog(@"hc >= 'A' && hc <='F'%c",hc);
}else { // 将小写'a'~'f'转化为10 - 15
int_ch += (hc-87)*z;
NSLog(@"else%c",hc);
}
//NSLog(@"[nbyte2Int] int_ch= %d", int_ch);
}
//================================================================
return int_ch;
}
如果socket是成功连接则无需再次注册,否则导致了(一直提示有人进入房间)
为什么重新初始化
屏幕快照 2018-12-25 下午9.23.31.png
网友评论