java.io.IOException:已建立的连接已被主机中的软件中止

时间:2016-01-26 14:26:09

标签: java websocket atmosphere

我正在使用wAsync库,Websocket协议和Atmosphere发送请求,请遵循以下文章: https://github.com/Atmosphere/wasync/wiki/Getting-Started-with-wAsync

以下是我实施的内容:

    try
    {
        AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class);
        RequestBuilder<?> requestBuilder =
            client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .uri(url)
                .trackMessageLength(false)
                .transport(Request.TRANSPORT.WEBSOCKET)        // Try Websocket.
                .transport(Request.TRANSPORT.LONG_POLLING);    // Fall back to Long pooling.

        final Socket socket = client.create();
        socket.open(requestBuilder.build()).fire(pMessage);
        socket.close();
    }
    catch (Exception e)
    {
    }

socket.fire成功运作。

但有时我收到以下错误:

15:11:36,467 ERROR [org.atmosphere.container.JSR356Endpoint] (http-localhost/127.0.0.1:8080-79) : java.io.IOException: An established connection was aborted by the software in your host machine
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.write0(Native Method) [rt.jar:1.7.0_76]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.access$900(WindowsAsynchronousSocketChannelImpl.java:43) [rt.jar:1.7.0_76]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$WriteTask.run(WindowsAsynchronousSocketChannelImpl.java:777) [rt.jar:1.7.0_76]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.implWrite(WindowsAsynchronousSocketChannelImpl.java:914) [rt.jar:1.7.0_76]
    at sun.nio.ch.AsynchronousSocketChannelImpl.write(AsynchronousSocketChannelImpl.java:381) [rt.jar:1.7.0_76]
    at sun.nio.ch.AsynchronousSocketChannelImpl.write(AsynchronousSocketChannelImpl.java:398) [rt.jar:1.7.0_76]
    at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:978) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.coyote.http11.InternalNioOutputBuffer$1.completed(InternalNioOutputBuffer.java:231) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.coyote.http11.InternalNioOutputBuffer$1.completed(InternalNioOutputBuffer.java:200) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126) [rt.jar:1.7.0_76]
    at sun.nio.ch.Invoker$2.run(Invoker.java:218) [rt.jar:1.7.0_76]
    at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) [rt.jar:1.7.0_76]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_76]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_76]
    at org.apache.tomcat.util.net.NioEndpoint$DefaultThreadFactory$1$1.run(NioEndpoint.java:1249) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_76]

15:11:36,469 ERROR [org.atmosphere.container.JSR356Endpoint] (http-localhost/127.0.0.1:8080-79) : java.io.IOException: An established connection was aborted by the software in your host machine
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.write0(Native Method) [rt.jar:1.7.0_76]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.access$900(WindowsAsynchronousSocketChannelImpl.java:43) [rt.jar:1.7.0_76]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$WriteTask.run(WindowsAsynchronousSocketChannelImpl.java:777) [rt.jar:1.7.0_76]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.implWrite(WindowsAsynchronousSocketChannelImpl.java:914) [rt.jar:1.7.0_76]
    at sun.nio.ch.AsynchronousSocketChannelImpl.write(AsynchronousSocketChannelImpl.java:381) [rt.jar:1.7.0_76]
    at sun.nio.ch.AsynchronousSocketChannelImpl.write(AsynchronousSocketChannelImpl.java:398) [rt.jar:1.7.0_76]
    at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:978) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.coyote.http11.InternalNioOutputBuffer$1.completed(InternalNioOutputBuffer.java:231) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.coyote.http11.InternalNioOutputBuffer$1.completed(InternalNioOutputBuffer.java:200) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126) [rt.jar:1.7.0_76]
    at sun.nio.ch.Invoker$2.run(Invoker.java:218) [rt.jar:1.7.0_76]
    at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) [rt.jar:1.7.0_76]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_76]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_76]
    at org.apache.tomcat.util.net.NioEndpoint$DefaultThreadFactory$1$1.run(NioEndpoint.java:1249) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_76]

此错误无法通过try-catch块捕获。

如果我删除socket.close(),则不会发生此错误。

有人知道为什么吗?我该怎么解决这个问题?或者有没有办法捕捉这个例外?

提前致谢!

***************** 更新 **********************

需要关闭套接字。

是否有一个我可以在开火操作完成时调用的回调方法?

0 个答案:

没有答案