WebSocket java客户端问题 - (从浏览器中正常工作)

时间:2016-04-27 09:04:47

标签: websocket tomcat8 java-ee-7 java-websocket

我正在尝试使用@ClientEndpoint为WebSocket编写一个java客户端。 服务器端点工作正常,因为我能够通过浏览器(JavaScript客户端)连接到它。但是每当我尝试使用java客户端连接到它时,我都会得到以下异常,但它并没有透露太多关于它自身的信息。 只是添加信息相同的项目在我的个人笔记本电脑上工作正常。然而,它在我的工作系统中失败了(可能是一些防火墙,但在这种情况下,我认为它应该作为javascript客户端失败)。

技术堆栈:Java 7,Tomcat 8 / Weblogic

修改 只是为了更新,使用 tyrus独立jar 我现在甚至可以从java客户端连接到WebSocket。但是当我通过Apache Tomcat 8连接时,问题仍然存在。

执行:

java.io.IOException: ConnectEx failed
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.connect0(Native Method)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.access$200(WindowsAsynchronousSocketChannelImpl.java:43)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ConnectTask.run(WindowsAsynchronousSocketChannelImpl.java:235)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.implConnect(WindowsAsynchronousSocketChannelImpl.java:382)
at sun.nio.ch.AsynchronousSocketChannelImpl.connect(AsynchronousSocketChannelImpl.java:198)
at weblogic.websocket.tyrus.client.proxy.Direct.connect(Direct.java:19)
at weblogic.websocket.tyrus.client.AIOWsClientSocket.openChannel(AIOWsClientSocket.java:151)
at weblogic.websocket.tyrus.client.AIOWsClientSocket.connect(AIOWsClientSocket.java:106)
at weblogic.websocket.tyrus.client.AIOWsClientContainer.openClientSocket(AIOWsClientContainer.java:41)
at org.glassfish.tyrus.client.ClientManager$1.run(ClientManager.java:426)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.glassfish.tyrus.client.ClientManager$SameThreadExecutorService.execute(ClientManager.java:620)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:110)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:351)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:187)
at MovieEventSocketClient.<init>(MovieEventSocketClient.java:22)
at HelloWorldServiceTest.initializeWebSocket(HelloWorldServiceTest.java:21)
at HelloWorldServiceTest.sendMessageOverSocket(HelloWorldServiceTest.java:27)
at HelloWorldServiceTest.main(HelloWorldServiceTest.java:37) 
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: ConnectEx failed
at MovieEventSocketClient.<init>(MovieEventSocketClient.java:25)
at HelloWorldServiceTest.initializeWebSocket(HelloWorldServiceTest.java:21)
at HelloWorldServiceTest.sendMessageOverSocket(HelloWorldServiceTest.java:27)
at HelloWorldServiceTest.main(HelloWorldServiceTest.java:37) 
Caused by: java.io.IOException: ConnectEx failed
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.connect0(Native Method)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.access$200(WindowsAsynchronousSocketChannelImpl.java:43)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ConnectTask.run(WindowsAsynchronousSocketChannelImpl.java:235)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.implConnect(WindowsAsynchronousSocketChannelImpl.java:382)
at sun.nio.ch.AsynchronousSocketChannelImpl.connect(AsynchronousSocketChannelImpl.java:198)
at weblogic.websocket.tyrus.client.proxy.Direct.connect(Direct.java:19)
at weblogic.websocket.tyrus.client.AIOWsClientSocket.openChannel(AIOWsClientSocket.java:151)
at weblogic.websocket.tyrus.client.AIOWsClientSocket.connect(AIOWsClientSocket.java:106)
at weblogic.websocket.tyrus.client.AIOWsClientContainer.openClientSocket(AIOWsClientContainer.java:41)
at org.glassfish.tyrus.client.ClientManager$1.run(ClientManager.java:426)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.glassfish.tyrus.client.ClientManager$SameThreadExecutorService.execute(ClientManager.java:620)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:110)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:351)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:187)
at MovieEventSocketClient.<init>(MovieEventSocketClient.java:22)
... 3 more

这是抛出错误的代码

@ClientEndpoint public class MovieEventSocketClient {   public MovieEventSocketClient(URI endpointURI) {        try {
        WebSocketContainer container = ContainerProvider
                .getWebSocketContainer();
        container.connectToServer(MovieEventSocketClient.class, endpointURI);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);

    }
}

0 个答案:

没有答案