1

I am trying to get my head around the objective c tcp socket to connect to server, I've used the code from those two tutorials: https://www.raywenderlich.com/3932/networking-tutorial-for-ios-how-to-create-a-socket-based-iphone-app-and-server and https://gist.github.com/rjungemann/446256. I noticed that when I am trying to send the data out its not send until I stop the application (at which point is received on the server), same behaviour when following both tutorials, below relevant code:

- (void)setup {
    NSURL *url = [NSURL URLWithString:host];

    NSLog(@"Setting up connection to %@ : %i", [url absoluteString], port);

    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)[url host], port, &readStream, &writeStream);

    if(!CFWriteStreamOpen(writeStream)) {
        NSLog(@"Error, writeStream not open");

        return;
    }
    [self open];

    NSLog(@"Status of outputStream: %lu", (unsigned long)[outputStream streamStatus]);

    return;
}

- (void)writeOut:(NSString *)s {
    uint8_t *buf = (uint8_t *)[s UTF8String];

    [outputStream write:buf maxLength:strlen((char *)buf)];

    NSLog(@"Writing out the following:");
    NSLog(@"%@", s);
}
jtbandes
  • 115,675
  • 35
  • 233
  • 266
geef
  • 65
  • 1
  • 2
  • 8
  • Did you schedule the stream on a run loop (using `scheduleInRunLoop:forMode:`)? – jcaron Jan 07 '17 at 00:11
  • You should also set a delegate to receive events on the stream which will give you more details about its status. BTW, both are clearly included in both of the tutorials you listed as well as Apple's Stream programming guide. – jcaron Jan 07 '17 at 00:13

1 Answers1

-2

Read on mother post, try adding \r\n to the string