I'm making a TCP protocol where an app sends JSON to a server and it sends JSON back. I am trying to delimit each transmission with a newline. This is fine on the server side, but how do you add a newline to each NSOutputStream write?
The streams are set-up correctly and here's the code I'm using to send data:
NSInteger sendJSON = [NSJSONSerialization writeJSONObject:dictionary toStream:self.outputStream options:0 error:nil];
How do you add a newline (\n
) to the end of that, surely there's a way?
Not forgetting that Objective C is a strict superset of C the simplest solution could be to add a new line after invoking the code in your question:
const char* newLine = "\n";
if (self.outputStream.hasSpaceAvailable) {
[self.outputStream write:(const uint8_t*)newLine maxLength:1];
}