Hey guys, I don't know if this question has been asked yet but imagine following situation:
I have two TCP-Sockets (opened with NSSocketPort
und listening with two NSFileHandle
) and now I want to send some NSData
between them.
@try {
[fileHandle writeData:data];
}
@catch (NSException * e) {
// Do some alert
}
Everything is right until I want to send a NSData
instance with more than a length of 32768 Bytes. More than this number of bytes will not be transfered. So here are my questions:
1) Why isn't Cocoa able to send more than 32768 Bytes at once?
2) Do I have to make workaround?
3) If yes, I would split the data, but how would you do it? And how would the other socket know when all data is sent?
By the way, after sending this single NSData
instance both sockets should be closed again.
The amount of data sent at a time depends on the size of the buffer which the underlying frameworks and libraries use. While it may be configurable, it's mostly irrelevant. The advantage of TCP is that it either guarantees to deliver your data (in one or more packets) or fails gracefully.