Guest User

Untitled

a guest
Jul 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
  2. NSString *message = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
  3. [data getBytes:&tdata];
  4. if (tdata > 5) {
  5.  
  6. if(bheader){
  7. if(!charS){
  8. if([message isEqualToString:@"S"]){
  9. CMSG = message;
  10. charS=YES;
  11. }
  12. }
  13. else{
  14. NSMutableString *tmp = [[NSMutableString alloc] initWithString:@""];
  15. [tmp appendString:CMSG]; <<<<< This is code error at loop 2,
  16. [tmp appendString:message]; the first loop success but second is fail
  17. CMSG = tmp;
  18. [tmp release];
  19. }
  20. }
  21. else{
  22. if (message){
  23. cmessage = [[NSString alloc]initWithFormat:@"%@%@",cmessage,message] ;
  24. }
  25. else
  26. NSLog(@"Error converting received data into UTF-8 String");
  27.  
  28. cdata++;
  29. if(cdata==idata) {
  30. msgComplete=YES;
  31. }
  32.  
  33. }
  34.  
  35. if (msgComplete) {
  36. NSDictionary *userInfo = [NSDictionary dictionaryWithObject:cmessage forKey:kNotificationMessage];
  37. [notificationCenter postNotificationName:kNotification object:self userInfo:userInfo];
  38. cmessage=@"";
  39. CMSG=@"";
  40. msgComplete=NO;
  41. bheader=YES;
  42. cdata=0;
  43. charS=NO;
  44. [cmessage release];
  45.  
  46. }
  47. }
  48.  
  49. [sock readDataToLength:1 withTimeout:-1 tag:0];
  50.  
  51. CMSG = tmp; //<< should be CMSG = [tmp retain];
  52. [tmp release];
  53.  
  54. [data getBytes:&tdata];
  55. if (tdata > 5) {
  56.  
  57. cmessage=@"";
  58. ...
  59. [cmessage release];
Add Comment
Please, Sign In to add comment