Closed artem-sherbachuk closed 8 years ago
Hey!
Well, that's pretty easy to explain: your app ran out of memory 😉. I have to admit that I have never really tried to send huge files even though the packet protocols support files up to 4GB (in theory).
At the moment I try to send the data block all at once. If the underlying stream was unable to write the data I chunk them. I can try to circumvent the issue by not creating a new data buffer for each chunk.
I'll keep you posted.
hey! ok thanks for an explanation :). Also, its will be great if possible to send not only UInt16 tag but also, String in one write. If it possible of corse, for example, encode main data and String as a tag - it can be id "asdkgjalkjgag123951alsd", action description "first.device.send.file.by.id" or whatever. This new protocol can be relly flexible.
thanks.
@jensmeder here is solution found here http://stackoverflow.com/questions/21252258/huge-memory-leaks-nsdata No more crashes.
-(BOOL)writeData:(NSData *)data
{
if (!data || data.length == 0 || _connectionState != JMSocketConnectionStateConnected)
{
return NO;
}
NSInteger bytesWritten = [_socket.outputStream write:data.bytes maxLength:data.length];
while (bytesWritten != data.length) {
@autoreleasepool {
NSRange range = NSMakeRange(bytesWritten, data.length - bytesWritten);
NSData* subData = [data subdataWithRange:range];
bytesWritten += [_socket.outputStream write:subData.bytes maxLength:subData.length];
}
}
if(bytesWritten > 0)
{
return YES;
}
return NO;
}
Nice! Thanks for sharing. I will incorporate your fix in the next release of DarkLightning this weekend.
I have incorporated your fix in version 1.0.1 . Sorry for the delay.
I use JMTaggedPacket to tagged file that I send. First I get data from file like this:
then it call write:
I use different tags that starts from 1 to 65535.
When JMSocketConnection calls writeData, if file large it crashes with error:
can you tell me what happens here? I send file from ios to mac and back.