I want to send small packages using the NSOutputStream in Objective-C.
I have the same problem this user has: Cocoa NSOutputStream send to a connection
An answer is to just add "\n" to the end of the string. I tried so and it does not work.
Does someone of you see my problem there? Might the encoding be the problem?
// Append the line break
theMessage = [theMessage stringByAppendingString:@"\n"];
// Create the data object
NSData *d = [theMessage dataUsingEncoding:NSASCIIStringEncoding];
// Send the message
[self.outputStream write:[d bytes] maxLength:[d length]]
Edit: I get the outputstream by calling this method from a NSNetservice-Object:
CFStreamCreatePairWithSocketToHost(NULL, url, port, &inputStream, &outputStream);
Edit2: The problem is that if I send a lot of messages very fast, the server recieves the message as one string, not as two seperated