我开发了基于 Spring 的 Web 应用程序来观看视频。它在桌面上运行良好。但是,如果我尝试从 iPad 和 iPhone 打开我的应用程序,我将无法播放视频。因为jwplayer无法从服务器获取数据。 jwplayer 显示“无法加载视频,可能是因为服务器或网络出现故障,或者格式不受支持”,同时服务器端错误是
Caused by: java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(Unknown Source)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.write(Unknown Source)
at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:170)
at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:221)
at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:725)
我在网上搜索了一下,找到了原因。 客户端(iPad/iPhone) 终止服务器连接。 这是断管异常。也请引用我的服务器端代码
private void sendFile(HttpServletResponse response, String filename, String directory, String contentType, String extention) throws IOException, InterruptedException {
final String file = directory + File.separator + filename + "." + extention;
response.setContentLength((int) new File(file).length());
response.setContentType(contentType);
try {
FileInputStream inputStream = new FileInputStream(file);
ServletOutputStream outputStream = response.getOutputStream();
IOUtils.copyLarge(inputStream, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
} catch (Exception exp) {
exp.printStackTrace();
}
response.setStatus(HttpServletResponse.SC_OK);
}
将 inputStream 复制到 outputStream 时发生 Broken Pipe,IOUtils.copyLarge(inputStream, outputStream)。
我该如何解决这个问题。任何人请以正确的方式指导我..
提前致谢..
最佳答案
解决哪个问题?不支持的视频问题的解决方法是发送一个支持的视频类型,破管道异常的解决方法是解决不支持的视频问题。
关于java - 为什么 iPad 和 iPhone 拒绝套接字连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21951427/