Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
- NSString *message = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
- [data getBytes:&tdata];
- if (tdata > 5) {
- if(bheader){
- if(!charS){
- if([message isEqualToString:@"S"]){
- CMSG = message;
- charS=YES;
- }
- }
- else{
- NSMutableString *tmp = [[NSMutableString alloc] initWithString:@""];
- [tmp appendString:CMSG]; <<<<< This is code error at loop 2,
- [tmp appendString:message]; the first loop success but second is fail
- CMSG = tmp;
- [tmp release];
- }
- }
- else{
- if (message){
- cmessage = [[NSString alloc]initWithFormat:@"%@%@",cmessage,message] ;
- }
- else
- NSLog(@"Error converting received data into UTF-8 String");
- cdata++;
- if(cdata==idata) {
- msgComplete=YES;
- }
- }
- if (msgComplete) {
- NSDictionary *userInfo = [NSDictionary dictionaryWithObject:cmessage forKey:kNotificationMessage];
- [notificationCenter postNotificationName:kNotification object:self userInfo:userInfo];
- cmessage=@"";
- CMSG=@"";
- msgComplete=NO;
- bheader=YES;
- cdata=0;
- charS=NO;
- [cmessage release];
- }
- }
- [sock readDataToLength:1 withTimeout:-1 tag:0];
- CMSG = tmp; //<< should be CMSG = [tmp retain];
- [tmp release];
- [data getBytes:&tdata];
- if (tdata > 5) {
- cmessage=@"";
- ...
- [cmessage release];
Add Comment
Please, Sign In to add comment