I’m getting troubles with tcp outputstream (json). It happens that the server receive my stream splitted in two pieces. But it has to be in just one.
Thats my code for send the stream:
- (void) sendMessage:(NSDictionary *)message {
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:@"52731255-7b3d-5027-9937-ca311e61c14e",@"token",@"add",@"action",message,@"data",@"contact",@"element", nil];
NSLog(@"send message: %@",dic);
NSError *writeError = nil;
[NSJSONSerialization writeJSONObject:dic toStream:outputStream options:0 error:&writeError];
}
But that’s what the server receives:
Incoming data:"{"
Incoming data:"\"action\":\"add\",\"data\":{\"lastName\":\"Guilherme\",\"firstName\":\"Fabio\",\"entryId\":3,\"webLink\":\"www.test.com\"},\"element\":\"contact\",\"token\":\"s3e4-7b3d-fasd-afds-fadsfdsa123\"}"
This happens in some cases, but on another cases the Incoming data, becomes in one piece.
The method to fix this, that we found, is to send a symbol in the end of the stream message. Like “/r/n” and the server closes the message when he sees it. So it just process one message at a time.