错误从Java连接到Websocket时未收到握手响应

时间:2019-06-26 10:30:31

标签: java-websocket tyrus

我正在尝试使用Java构建WebSocket客户端。我们收到以下错误作为对connectToServer方法的响应。有人可以帮助我们吗?

javax.websocket.DeploymentException:未收到握手响应。     在org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:300)     在org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:172)     在smartsense.wss.client.NewWebSocket。(NewWebSocket.java:22)     在smartsense.wss.client.App.main(App.java:21)

文件中使用的导入

   import java.io.IOException;
   import java.net.URI;

   import javax.websocket.*;

源代码

   try {
       WebSocketContainer container = ContainerProvider.getWebSocketContainer();
       session = container.connectToServer(this, new URI(uri));
   } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (session != null) {
                try {
                    session.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

pom.xml中的依赖项

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.websocket</groupId>
      <artifactId>javax.websocket-api</artifactId>
      <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>
    <dependency>
       <groupId>org.glassfish.tyrus</groupId>
       <artifactId>tyrus-client</artifactId>
       <version>1.1</version>
    </dependency>
    <dependency>
       <groupId>org.glassfish.tyrus</groupId>
       <artifactId>tyrus-container-grizzly</artifactId>
       <version>1.1</version>
    </dependency>
    <dependency>
       <groupId>javax.json</groupId>
       <artifactId>javax.json-api</artifactId>
       <version>1.0</version>
    </dependency>
    <dependency>
       <groupId>org.glassfish</groupId>
       <artifactId>javax.json</artifactId>
       <version>1.0.1</version>
    </dependency>   
  </dependencies>

编辑 当我从组织网络(在代理后面)尝试时,我仅收到“ javax.websocket.DeploymentException:握手响应未收到。     出现错误。

但是当我尝试使用自己的Internet连接时,我可以看到也触发了“ onClose”方法,然后触发了“ javax.websocket.DeploymentException:未收到握手响应”。     在“错误

仍然停留在同一地方,任何帮助都值得赞赏。还是任何人都可以告诉一个好的Java Web Socket客户端库?

0 个答案:

没有答案