Objective C TCP Socket with NSStream: Client [Cocoa Asynchronous Socket]

You may also like...

  • vikas

    Hi, I used the explained client program. i have a Linux socket based

    server program, The client program is able to connect to linux socket
    based server but it is not able to send any packet to it….. could you
    share any pointer as in what can be th root cause ? Am i missing
    something basic?

    • make sure nsstream in run loop, its async socket, you are missing event passed by kernel to your program

      • vikas

        You are a gem!!! i never expected a reply so quick. well as in the code i can see. nsstream is in loop…
        code from main function
        -(void)main{
        CFRunLoopSourceRef loopref=CFSocketCreateRunLoopSource(kCFAllocatorDefault, obj_client, 0);
        CFRunLoopAddSource(CFRunLoopGetCurrent(), loopref, kCFRunLoopDefaultMode);
        CFRelease(loopref);
        NSLog(@”Client is running”);
        CFRunLoopRun();
        }

  • vikas

    You are a gem!!! Never expected reply so early… as i could see in the code nsstream is in the loop….

    -(void)main{
    CFRunLoopSourceRef loopref=CFSocketCreateRunLoopSource(kCFAllocatorDefault, obj_client, 0);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), loopref, kCFRunLoopDefaultMode);
    CFRelease(loopref);
    NSLog(@”Client is running”);
    CFRunLoopRun();
    }

    Thanks for help so far…

    • if you followed code as per video, you need to read the initial bit, which trigger the write, then you will get your data
      recv data format: initial byte length 1, then your data bytes

      • vikas

        how does the stream function is called??? i used lldb to debug .. it seems stream function is not being called at all.

      • vikas

        How stream function is being called? somehow my comments are being lost 🙁

        • Comments are monitored, visible after approval

  • vikas

    how does the stream function is called??? i used lldb to debug .. it seems stream function is not being called at all.

    • Kernal pass event on data recv and app handles these event, and stream write initiate by user, kernel handles unsent bytes,
      debug your code with breakpoint