- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
当某些请求到达服务器(在移动应用程序上运行的服务器)时,我正在尝试提供视频文件作为响应。例如:有人去 http://mylocalip:8080/video ,我想用视频服务他。
这个视频文件可以存储在本地,也可以是外部的。我开始尝试提供位于 SMB 服务器上的文件,所以我尝试使用此代码从服务器获取文件并将其返回(我知道它正在等待读取整个文件而不是读取和发送 block ,但应该可以工作对吧?):
webServer.addDefaultHandlerForMethod("GET", requestClass: GCDWebServerRequest.self, processBlock: {request in
print("########\n########Request: \(request)")
let webrequested:GCDWebServerRequest = request;
let urlcita:String = String(webrequested.URL)
print("URL of requests\(urlcita)")
if urlcita.rangeOfString("videosmb") != nil{
print("It's a video SMB request")
//Test fake SMB file predefined. Read File using KxSMB
let route:String = "smb://192.168.1.205/ServidorAH/video.avi";
let extensFile:NSString = (route as NSString).pathExtension
let contentype = GCDWebServerGetMimeTypeForExtension(extensFile as String);
print("Content type MIME \(contentype)")
//Open SMB file using KxSMB
let authcredentials = KxSMBAuth.smbAuthWorkgroup("", username: "Guest", password: "");
let provider = KxSMBProvider.sharedSmbProvider()!
let archivoes = provider.fetchAtPath(route, auth: authcredentials)
//Switch to manually end the reading when switched to true. In the future will send chunks of data until the end, instead of reading the whole file first.
var interruptor:Bool = false
//Response Stream block
let responseStream: GCDWebServerStreamedResponse = GCDWebServerStreamedResponse(contentType: contentype, asyncStreamBlock: { completionBlock in
if (interruptor == true)
{
print("Test: End of reading")
completionBlock(NSData(), nil);
}
if archivoes!.isKindOfClass(NSError){
//It can not find the file, SMB error, so empty NSDATA to completion block
let errorcito:NSError = archivoes as! NSError
print("Error obteniendo archivo SMB: \(errorcito.localizedDescription)");
completionBlock(NSData(), nil);
}else{
print("Archivo SMB adecuado \(archivoes)")
let datos:NSData = archivoes!.readDataToEndOfFile()
//Print lenght of data (to check the size of the file)
print("Data lenght \(datos.length)")
//Set switch to true, so the next call will send an empty daya completion block
interruptor = true
//Send data chunk (in this case everything)
completionBlock(datos, nil);
}
})
return responseStream
}else{
//Default response
return GCDWebServerDataResponse(HTML:"<html><body><p>Hello World<br></p></body></html>")
}
但是,我无法让它工作。我总是遇到管道损坏错误,并且访问网络服务器的网络播放器(也从 Mac 和 iOS 浏览)不播放任何内容。我还尝试使用嵌入式 iOS 播放器来记录响应 (KxMovie)。我得到这样的东西:
[DEBUG] Did open connection on socket 19
[DEBUG] Connection received 177 bytes on socket 19
[DEBUG] Connection on socket 19 preflighting request "GET /videosmb" with 177 bytes body
[DEBUG] Connection on socket 19 processing request "GET /videosmb" with 177 bytes body
[DEBUG] Did connect
[DEBUG] Did start background task
[DEBUG] Connection sent 175 bytes on socket 19
...
使用应用程序内部的本地播放器 (KxMovie),这里似乎是在读取文件 header ,并获得正确的文件大小和视频尺寸。但是它不播放并且结束时说它到达了视频的结尾(没有播放)。紧接着,WebServer 显示错误:
...
[ERROR] Error while writing to socket 19: Broken pipe (32)
[DEBUG] Did close connection on socket 19
[VERBOSE] [fe80::cd0:28cd:3a37:b871%en1:8080] fe80::cd0:28cd:3a37:b871%en1:50109 200 "GET /videosmb" (177 | 175)
[DEBUG] Did disconnect
[DEBUG] Did end background task
考虑到这是我第一次与 SMB 服务器打交道,我想也许我在 SMB 部分做错了什么,所以我决定采用一种仅用于测试的简化方法。这次我尝试提供一个存储在远程网络服务器(不是 SMB)上的简单 mp4 文件。它也没有用。最后,我尝试提供包含在应用程序主 bundle 中的本地文件,同样的事情发生了:什么都没有。这是代码:
webServer.addDefaultHandlerForMethod("GET", requestClass: GCDWebServerRequest.self, processBlock: {request in
print("########\n########Request: \(request)")
let webrequested:GCDWebServerRequest = request;
let url:String = String(webrequested.URL)
print("URL of request: \(url)")
if url.rangeOfString("video") != nil{
print("It's a video request")
let rutalocalita = (NSBundle.mainBundle()).pathForResource("video", ofType: "avi")
let datos = NSData(contentsOfFile: rutalocalita!)!
print("video size: \(datos.length)")
return GCDWebServerDataResponse(data: datos, contentType: "video/avi")
}else{
//Default Response: Simple web
return GCDWebServerDataResponse(HTML:"<html><body><p>Hello World<br></p></body></html>")
}
})
这是日志的样子:
[DEBUG] Did open connection on socket 19
[DEBUG] Connection received 177 bytes on socket 19
[DEBUG] Connection on socket 19 preflighting request "GET /video" with 177 bytes body
[DEBUG] Connection on socket 19 processing request "GET /video" with 177 bytes body
[DEBUG] Did connect
[DEBUG] Did start background task
[myCUSTOMDebug] Read 13584902 b. I'm going to send the response back to the request.
[DEBUG] Connection sent 173 bytes on socket 19
...
这里是我在应用程序内部使用的本地播放器来跟踪响应,能够读取如下内容:
header='HTTP/1.1 200 OK'
2015-10-17 17:51:41.571 videotvtest[262:14252] http_code=200
2015-10-17 17:51:41.571 videotvtest[262:14252] header='Cache-Control: no-cache'
2015-10-17 17:51:41.571 videotvtest[262:14252] header='Content-Length: 13584902'
2015-10-17 17:51:41.572 videotvtest[262:14252] header='Content-Type: video/avi'
2015-10-17 17:51:41.572 videotvtest[262:14252] header='Connection: Close'
2015-10-17 17:51:41.573 videotvtest[262:14252] header='Server: GCDWebServer'
...
[ERROR] Error while writing to socket 19: Broken pipe (32)
[DEBUG] Did close connection on socket 19
[VERBOSE] [fe80::cd0:28cd:3a37:b871%en1:8080] fe80::cd0:28cd:3a37:b871%en1:50155 200 "GET /video" (177 | 173)
netbios_ns_send_name_query, name query sent for '*'.
[DEBUG] Did disconnect
[DEBUG] Did end background task
为此我正在尝试使用 tvOS 和 Xcode 7,但我想如果我能够显示常规 HTML 响应应该没问题...所以我确定我遗漏了什么,或者也许我在安装 WebServer 时错过了一些框架(我没有使用 Pod)?提前致谢
最佳答案
如果您想要使用视频标签提供可以在浏览器中播放的视频文件,至少在 Chrome 和 Safari 上,您需要实现 HTTP 范围请求。
如果您使用 GCDWebServerFileResponse
,GCDWebServer 会自动实现范围支持。如果您使用其他类型的响应,则需要根据传入的 GCDWebServerRequest
的 byteRange
属性自行实现。您应该从 GCDWebServerFileResponse.m
复制粘贴逻辑。
关于ios - 如何为某些请求提供远程文件(从远程 SMB 服务器获取),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33188728/
我正在尝试使用 JCIFS 将一些远程文件复制到本地驱动器,在 Java 中。 远程机器在域内。本地机器不在域中。 下面的代码有效,但它真的很慢(700Kb 需要 2 分钟......而且我有很多 M
我必须更新使用适用于 Windows Server 2012 的 JCIFS 的旧文件共享软件。出于安全目的,我们必须禁用 SMB 1.0/CIFS 兼容性。有谁知道可以在 Java 中使用的 JCI
在下面的代码语句中: SmbFileInputStream din==new SmbFileInputStream(src); 我正在尝试创建一个 SmbFileInputStream 对象。如果 S
在 Mac 上,我有一个共享文件夹 ~\Documents。有两个子文件夹:Data 和 Data_2011,前者包含过去几年的文件文件夹,后者包含指向 Data 文件夹中自 2011 年 1 月 1
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
要读取 R 中的文件,我通常会执行如下操作: read.csv('/Users/myusername/myfilename.csv') 但是,我正在尝试读取位于远程服务器(Windows SMB/CI
我正在尝试通过 JCIFS 访问公司网络中的共享文件夹。但是当我尝试列出共享文件夹下的文件时,它会抛出 SmbException,如下所示, jcifs.smb.SmbException: 0xC00
我正在尝试将 jar 文件复制到 Windows 共享文件夹,并且使用 smb 来执行此操作,但出现以下错误。还有其他方法可以复制文件吗? String user = "abc"; S
如何将 Mplayer 移植到 iOS?并使其支持 SMB? 我构建了ffmpeg,但另一件事是我不知道如何使这个支持smb。 我想要的是在 iOS 上开发一个支持 smb 的播放器。 最佳答案 我在
我知道 smbclient 不允许输出重定向,但是否有任何解决方法可以将输出输出到文本文件或标准文件? 最佳答案 你试过这个吗: $ smbclient -U USER%PASSWORD //IPTO
命令行的mac上的“连接到服务器”等效于什么? 我想自动化这个过程,而不是每次需要连接到服务器时都调用对话框。 最佳答案 有多种方法可以连接到远程服务器! 我假设您有在 Windows 操作系统上运行
我正在寻找一种在 SMB 远程共享上检索比某个日期/时间更新的文件的方法,所有这些都在 Windows 下工作。我一直在使用DirectoryInfo.EnumerateFiles() ,并在返回时进
我有一个文件存储在服务器中,路径如下:\\myserver\folder\myfile.txt 如何将此 SMB 地址放入带有超链接的单元格中? Hyperlink link = createHelp
在 PowerShell 中: PS> (Get-SmbConnection)[0].Encrypted 我如何在 C# 中执行此操作? 最佳答案 这是一个 WMI 方法。要在 C# 中做到这一点,您
我在删除方法上收到以下错误: jcifs.smb.SmbException:进程无法访问该文件,因为该文件正在被另一个进程使用。 如何确保文件没有被锁定以便可以将其删除? 我的代码: try{
我正在开发一个 Android 应用程序,它可以在 Windows PC 上写入和读取文件 (*.txt)。该应用程序连接到 WiFi 网络并使用 SMB。当网络有互联网连接时,该应用程序运行良好。当
是否可以使用 jcifs 列出网络上所有可用的 smb 服务器?我尝试了另一篇将 smb:// 传递给 SmbFile 构造函数的建议,但没有给我任何结果。而我能够传递 smb://username:
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我在 Android SDK 中使用 Smb。 我有下一个代码: public AuthListFiles() throws Exception { 1 SmbFile file = n
我一直在尝试找到一种通过 swift 2 和 Xcode 7 连接到我的网络驱动器的方法。我可以连接到我的桌面或文档目录,但不能连接到我的服务器。我玩过 NSString/NSURL 等但无济于事。以
我是一名优秀的程序员,十分优秀!