Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建Iphone的MJPEG查看器_Iphone_Objective C_Asyncsocket_Mjpeg - Fatal编程技术网

创建Iphone的MJPEG查看器

创建Iphone的MJPEG查看器,iphone,objective-c,asyncsocket,mjpeg,Iphone,Objective C,Asyncsocket,Mjpeg,我试图在Objective C中创建一个MJPEG查看器,但是我遇到了很多问题 首先,我使用AsyncSocket()连接到主机 这是我到目前为止得到的 NSLog(@"Ready"); asyncSocket = [[AsyncSocket alloc] initWithDelegate:self]; //http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi NSError *err = nil; if(![asyncSocket connectT

我试图在Objective C中创建一个MJPEG查看器,但是我遇到了很多问题

首先,我使用AsyncSocket()连接到主机

这是我到目前为止得到的

NSLog(@"Ready");
asyncSocket = [[AsyncSocket alloc] initWithDelegate:self];
//http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi
NSError *err = nil;
if(![asyncSocket connectToHost:@"kamera5.vfp.slu.se" onPort:80 error:&err])
{
    NSLog(@"Error: %@", err);
}
然后在didConnectToHost方法中:

 - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port{
NSLog(@"Accepted client %@:%hu", host, port);


NSString *urlString = [NSString stringWithFormat:@"http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"GET"];

    //set headers
NSString *_host = [NSString stringWithFormat:host];
[request addValue:_host forHTTPHeaderField: @"Host"];

NSString *KeepAlive = [NSString stringWithFormat:@"300"];
[request addValue:KeepAlive forHTTPHeaderField: @"Keep-Alive"];

NSString *connection = [NSString stringWithFormat:@"keep-alive"];
[request addValue:connection forHTTPHeaderField: @"Connection"];


//get response
NSHTTPURLResponse* urlResponse = nil;  
NSError *error = [[NSError alloc] init];  
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; 

NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
    NSLog(@"Response: %@", result);
            //here you get the response
}
-(void)onSocket:(AsyncSocket*)sock didConnectToHost:(NSString*)主机端口:(UInt16)端口{
NSLog(@“接受的客户端%@:%hu”,主机,端口);
NSString*urlString=[NSString stringWithFormat:@]http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi"];
NSMutableURLRequest*请求=[[[NSMutableURLRequest alloc]init]autorelease];
[请求设置URL:[NSURL URLWithString:urlString]];
[请求设置HttpMethod:@“获取”];
//设置标题
NSString*_host=[NSString stringWithFormat:host];
[请求addValue:_hostfor HttpHeaderField:@“host”];
NSString*KeepAlive=[NSString stringWithFormat:@“300”];
[请求addValue:KeepAlive for HttpHeaderField:@“保持活动状态”];
NSString*连接=[NSString stringWithFormat:@“保持活动状态”];
[请求添加值:HttpHeaderField的连接:@“连接”];
//得到回应
NSHTTPURLResponse*urlResponse=nil;
NSError*error=[[NSError alloc]init];
NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&urlResponse错误:&error];
NSString*result=[[NSString alloc]initWithData:responseData编码:NSUTF8StringEncoding];
NSLog(@“响应代码:%d”,[urlResponse statusCode]);
如果([urlResponse statusCode]>=200&&[urlResponse statusCode]<300){
NSLog(@“响应:%@”,结果);
//这是你得到的答复
}
}

这会调用MJPEG流,但它不会调用它来获取更多数据。我认为它所做的只是加载第一块数据,然后断开连接

我这样做是完全错误的还是这条隧道的尽头有光明


谢谢

尝试在UiWebView中加载mjpeg,它应该能够以本机方式播放

假设您有一个名为“myWebView”的UiWebView,类似这样的功能应该可以工作:

NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi"]];
[myWebView loadRequest:urlRequest];

我希望这有帮助

这可能最好用JavaScript来完成,因为没有一种好的方法可以与UIWebView进行通信。

主要问题是webkit从不释放数据,所以过了一段时间数据就会爆炸。

任何人都能帮上忙吗???求你了……我想我能做到。我只是觉得有更好的办法。谢谢在我看来,当最简单的方法可以完成任务时,让你的生活复杂化是没有用的有证据证明吗?做了一个5兆焦耳的测试,内存使用在30分钟内没有增长