java - 为什么 iPad 和 iPhone 拒绝套接字连接?

标签 java ipad sockets network-programming

我开发了基于 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/

相关文章:

java - 修改可选<Person>(如果存在)

java Runtime.getRuntime().exec 无法获取某些命令的输出

iphone - 我可以在 iPad 应用程序中获取 iPhone 数字键盘吗?

c# - 如何使TCP套接字保持事件状态并检测断开连接?

android - Android 应用程序可以使用套接字与 native Android 服务通信吗?

java - 制作android游戏: can not acces my SharedPreferences in class which extends SurfaceView implements SurfaceHolder.回调

java - 如何使用maven为Spring指定loadTimeWeaver

ios - 在 UISplitView 的 rootviewcontroller 中设置异常酷炫的选项卡栏

iphone - 将NSMutableIndexSet的每个元素加1

java - 应用程序在 intelliJ 中运行但 .jar 未运行