简体   繁体   English

Websocket Wss 连接失败

[英]Websocket Wss connection failed

everyone.每个人。 I'm trying to apply the websocket to our server.我正在尝试将 websocket 应用到我们的服务器。

I used the websocket provided by Javax, succeeded in connecting in my local environment, and sent a message to the client.我用的是javax提供的websocket,在我本地环境连接成功,给客户端发了消息。

However, as a result of applying it to the server, the connection is failing.但是,由于将其应用于服务器,连接失败。 The difference from the local environment is that the protocol uses wss instead of ws.与本地环境不同的是协议使用wss而不是ws。

Currently, our server is using SSL. Is it related to this?目前我们服务器使用的是SSL,跟这个有关系吗?

Please Help.请帮忙。 Please help!请帮忙!

Code at client side (Javascript)客户端代码(Javascript)

```
var protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
var hostPort = location.host;
var webSocket = new WebSocket(protocol+"//"+hostPort+$B.path+"/websocket");
```

Code at Server side (Java)服务器端代码(Java)

@ServerEndpoint("/websocket")
public class WebSocket {
    private static final Logger logger = LogManager.getLogger(WebSocket.class);
    public static Session session;
    @OnOpen
    public void handleOpen(Session session) {
        this.session = session;
        String username = "";
        try {
            session.getBasicRemote().sendText("You are connected. Your ID is" + session);
            // sessions.put("",session);
        } catch (Exception e) {
            logger.error("Error on open web socket", e);
        }
    }

Error at the browser console:浏览器控制台错误:

VM1435:4 WebSocket connection to 'wss://framptest.bizflow.com/bizflowappdev/websocket' failed: 

I already solves this problem.我已经解决了这个问题。 It's related with apache.与apache有关。

I add proxypass localhost:8080/websocketPath to http conf file.我将 proxypass localhost:8080/websocketPath添加到 http conf 文件。

That result, I success connect using wss protocol.结果,我使用 wss 协议成功连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM