Note that there are some explanatory texts on larger screens.

plurals
  1. POReading Data using CocoaAsyncSocket returns blanks
    primarykey
    data
    text
    <p>I have created a TCP Sockets connection using CocoaAsyncSocket and whenever I try to perform didReadData, I'm getting back blanks. I found the value of "msg" was @"" when I set break points and tried to debug. </p> <p>This is what my appDelegate.m looks like:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSData *data = nil; // Initialize socket object and make it a delegate. Then call the delegate methods. socket = [[AsyncSocket alloc] initWithDelegate:self]; [self connect]; [self onSocket:socket didConnectToHost:@"9.5.8.6" port:11005]; [self onSocket:socket didReadData:data withTag:1]; // tags COULD be #defined ******* self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[tekMatrixViewController alloc] initWithNibName:@"tekMatrixViewController" bundle:nil] autorelease]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } </code></pre> <p>And here is my onSocket:socket didReadData:data withTag: method:</p> <pre><code>- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { NSData *strData = [data subdataWithRange:NSMakeRange(0, [data length])]; NSString *msg = [[NSString alloc] initWithData:strData encoding:NSUTF8StringEncoding]; if(msg) { NSLog(@"RX:%@",msg); if(msg == nil) { NSLog(@"msg is all Blanks"); } } else { NSLog(@"Fail"); } } </code></pre> <p>Note, this method is a method from the CocoaAsyncLibrary. I do not know if I'm invoking the method properly or if I'm not passing the correct arguments, or what. </p> <p>When I run the app, all I see in my console is:</p> <pre><code>2012-06-06 11:44:00.434 tekMatrix[1378:f803] connected 2012-06-06 11:45:14.312 tekMatrix[1378:f803] RX: </code></pre> <p>Any and all help is very much appreciated. </p> <p>Thanks!</p> <p><em>EDIT</em></p> <p>Here is what I have in my didFinishLaunchingWithOptions method now:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { socket = [[AsyncSocket alloc] initWithDelegate:self]; NSError *error = nil; if (![socket connectToHost:@"199.5.83.63" onPort:11005 error:&amp;error]) { NSLog(@"Error connecting: %@", error); } self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[tekMatrixViewController alloc] initWithNibName:@"tekMatrixViewController" bundle:nil] autorelease]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } </code></pre> <p>Now I'm able to see that I'm connected, but I'm still not understanding onSocket:socket didReadData:data withTag: method is not be invoked. Any help on this would be much appreciated. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload