iOS CocoaHttpServer文件下载速度极慢

iOS CocoaHttpServer文件下载速度极慢,ios,objective-c,iphone,performance,cocoahttpserver,Ios,Objective C,Iphone,Performance,Cocoahttpserver,我目前正在iPhone中构建一个http服务器,允许wifi扬声器从中下载音乐。到目前为止,我所做的就是: 这是初始化http服务器的部分: 这是获取音乐文件的资产URL的部分: 我的问题是: 50%的情况下,要么音乐文件无法从服务器下载,要么下载速度极慢,低于10kb/s。我的问题是我不知道这个问题的可能原因是什么,我怎样才能解决这个问题 不同的例子: 有时在开始时,下载速度为OK下载速度为200+kb/s,然后不做任何事情,速度会突然下降,使扬声器完全无法从服务器获取文件。请注意,没有其他设

我目前正在iPhone中构建一个http服务器,允许wifi扬声器从中下载音乐。到目前为止,我所做的就是:

这是初始化http服务器的部分:

这是获取音乐文件的资产URL的部分:

我的问题是:

50%的情况下,要么音乐文件无法从服务器下载,要么下载速度极慢,低于10kb/s。我的问题是我不知道这个问题的可能原因是什么,我怎样才能解决这个问题

不同的例子:

有时在开始时,下载速度为OK下载速度为200+kb/s,然后不做任何事情,速度会突然下降,使扬声器完全无法从服务器获取文件。请注意,没有其他设备连接到路由器,只有扬声器和电话

有时在开始时,歌曲没有播放,然后几秒钟后开始播放

有一次我试着把8个扬声器连接到一个路由器上,播放起来很流畅。但在一个小时或更短的时间后,问题就会出现,就像很多次停车一样

我尝试过的解决方案:

尝试在不同类型的路由器下连接所有扬声器 TP-LINK、天达、Netgear、mi等。。。。上述情况仍然存在

当歌曲停止播放或收到的数据非常慢时,我尝试重新启动应用程序,重新启动手机,甚至重新启动路由器,但开始时速度仍然非常慢

已尝试断开路由器与调制解调器的连接

尝试仅连接四台设备和一部电话

5.尝试关闭不在同一网络下的所有其他wifi设备

已尝试更改http服务器的端口

当问题发生时,我尝试检查连接是否断开,或者http服务器是否关闭。但两者都可以

注意:

我尝试使用浏览器访问url,下载速度与说话者播放歌曲时的速度一样慢。所以我想问题不在演讲者身上

当问题发生时,根本没有返回任何错误消息

在NSLog上检查时,没有连接终止

我的请求:

所以请,如果你们有一个什么可能导致这个问题的想法,请告诉我,或者更好,如果你知道这个问题的解决办法。很难确定问题出在哪里。因为没有反映错误消息,我尝试删除了很多可能导致此问题的内容,但仍然没有得到好的结果

任何帮助都将不胜感激

- (void)startHttpServer
{
  [DDLog addLogger:[DDTTYLogger sharedInstance]];

  _httpServer = [[HTTPServer alloc] init];
  [_httpServer setType:@"_http._tcp."];

  NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

  [_httpServer setDocumentRoot:documentPath];
  [_httpServer setPort:9088];
  [_httpServer setName:@"Music Server"];

  [self startServer];  }
if (currentGroupIndex < currentGroupPlayList.count)
{
   [self.savedIndexInfo setObject:[NSNumber numberWithInteger:currentGroupIndex] forKey:groupIDNum];

    //makes sure that there is no existing duplicated url;
    NSURL *oneURL = [self.savedURLInfo objectForKey:groupIDNum];
    [[NSFileManager defaultManager] removeItemAtURL:oneURL error:nil];

    MPMediaItem *music = [currentGroupPlayList objectAtIndex:currentGroupIndex];
    NSURL *assetURL = [music valueForProperty:MPMediaItemPropertyAssetURL];

    [self exportAssetAtURL:assetURL
                 withTitle:[NSString stringWithFormat:@"song_%lld_%ld", groupID, (long)currentGroupIndex]
               groupAdress:groupIP
                   groupID:groupID
              songDuration:[[music valueForProperty:MPMediaItemPropertyPlaybackDuration]intValue]];
}
- (void)exportAssetAtURL:(NSURL*)assetURL withTitle:(NSString*)title groupAdress:(NSString *)groupAdress groupID:(UInt64)groupID songDuration:(NSInteger)duration 
{ 

   NSString *ext = [TSLibraryImport extensionForAssetURL:assetURL];
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentsDirectory = [paths objectAtIndex:0];
   NSURL *outURL = [[NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:title]] URLByAppendingPathExtension:ext];

    // we're responsible for making sure the destination url doesn't already exist
   [[NSFileManager defaultManager] removeItemAtURL:outURL error:nil];

    // create the import object
   TSLibraryImport* import = [[TSLibraryImport alloc] init];

   [import importAsset:assetURL toURL:outURL completionBlock:^(TSLibraryImport* import)
    {
        if (import.status == AVAssetExportSessionStatusCompleted)
        {
            NSString *musicURL = [NSString stringWithFormat:@"http://%@:9088/%@.%@", [self currentIPAddress], title, ext];
            NSLog(@"URL: %@", musicURL);

            cntl_http_pb_pkt pb;
            pb.header.packet_type = CONTROL_PACKET;
            pb.header.op = CNTL_PB_HTTP_PLAY;
            pb.header.body_len = sizeof(pb.body);

            const char *adressChar = [groupAdress cStringUsingEncoding:NSASCIIStringEncoding];
            pb.body.group_addr = inet_addr(adressChar);
            pb.body.group_port = htons(INIT_GROUP_PORT);
            pb.body.seq = [NSDate timeIntervalSinceReferenceDate];
            self.playSeq = pb.body.seq;

            const char *urlChar = [musicURL cStringUsingEncoding:NSASCIIStringEncoding];
            memcpy(pb.body.url, urlChar, 200);

            NSData *data = [NSData dataWithBytes:&pb length:sizeof(pb)];

            [self.savedURLInfo setObject:outURL forKey:[NSNumber numberWithUnsignedLongLong:groupID]];
            [self.savedPlayData setObject:musicURL forKey:[NSNumber numberWithUnsignedLongLong:groupID]];

            [self performSelectorOnMainThread:@selector(sendUdpData:) withObject:data waitUntilDone:YES];

            _acting = NO;
        }

        else
        {
            _acting = NO;
            NSLog(@"Error importing: %@", import.error);
        }

        import = nil;
    }];
}