0

I'm having an NSData object of approximately 50MB large. Now I want to transfer this via udpSocket.but 2kb up data not send....how to convert this nsdata small file or data approximately 2kb.

I'm use this code to send nsdata:

- (IBAction)send:(id)sender
{
NSString *host = addrField.text;

if ([host length] == 0)
{
    [self logError:@"Address required"];
    return;
}

int port = [portField.text intValue];
if (port <= 0 || port > 65535)
{
    [self logError:@"Valid port required"];
    return;
}

NSString *msg = [[NSBundle mainBundle] pathForResource:@"veer" ofType:@"mp3"];
if ([msg length] == 0)
{
    [self logError:@"Message required"];
    return;
}

NSData* data =[[NSData alloc]init];
data= [NSData dataWithContentsOfFile:msg];



[udpSocket sendData:data toHost:host port:port withTimeout:-1 tag:tag];
NSLog(@"%ld",tag);

[self logMessage:FORMAT(@"SENT (%i): %@", (int)tag, msg)];
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self  delegateQueue:dispatch_get_main_queue()];

//omitted error checking
[udpSocket bindToPort:port error:nil];
[udpSocket joinMulticastGroup:host error:nil];
[udpSocket beginReceiving:nil];


tag++;
 }

send only 2200 byte size not nsdata.2200 byte up(large)data not send please give any solution.

Gami Nilesh
  • 581
  • 4
  • 19
  • `subdataWithRange:`? – Larme Sep 30 '14 at 10:28
  • 5961728 byet up nsdata – Gami Nilesh Sep 30 '14 at 10:33
  • 1
    Did you look at the doc of `subdataWithRange:`? It could be what you are looking for. Also, the line `[[NSData alloc]init];` is useless. – Larme Sep 30 '14 at 10:37
  • i alloc nsdata see code – Gami Nilesh Sep 30 '14 at 10:39
  • 1
    It seems that `udpSocket:didNotSendDataWithTag:dueToError:` should be called. Also, why don't you use `subdataWithRange:` to cut your large data into small ones? The max size is can't be outdone apparently, due to system: http://stackoverflow.com/questions/9123098/set-max-packet-size-for-gcdasyncudpsocket – Larme Sep 30 '14 at 13:29
  • you say but i not understand please say with code – Gami Nilesh Sep 30 '14 at 13:32
  • Something like that:? `for (int i = 0; i < [data length]/maxSize; i ++){NSData *aSmallPart = [data subdataWithRange:NSMakeRange(i*maxSize;maxSize)]; //+ checking if you are at the end, so it could be NSMakeRange(i*maxSize;[data lenght]-i*maxSize) or something like that; [udpSocket sendData:aSmallPart ZzZ];` – Larme Sep 30 '14 at 13:36
  • what is this value maxSize how to declare this – Gami Nilesh Sep 30 '14 at 13:39
  • thanks but please send proper i not understend please – Gami Nilesh Sep 30 '14 at 14:16
  • In the previous SO link, there is clearly mention of `maxReceiveIPv4BufferSize`. Did you look at it? I don't understand what you do not understand. It seems to me quite clear that you have to divide your large data into small data parts. So what's wrong? What have you tried? – Larme Sep 30 '14 at 14:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62227/discussion-between-gami-nilesh-and-larme). – Gami Nilesh Oct 01 '14 at 06:05

0 Answers0