JAVA获得websocket请求路径前缀

 

 /**
     * 获得websocket请求路径前缀(线程安全 速度相对慢)
     * @param request
     * @return
     */
    public static String getWebsocketUrl(HttpServletRequest request) {
        StringBuffer buffer=new StringBuffer();
        buffer.append("ws://")
                .append(request.getServerName())
                .append(":")
                .append(request.getServerPort())
                .append(request.getContextPath())
                .append("/");
        return buffer.toString();
    }

 

 

/**
     * 获得websocket请求路径前缀(线程不安全 速度相对快)
     * @param request
     * @return
     */
    public static String getWebsocketUrl(HttpServletRequest request) {
        StringBuilder builder=new StringBuilder();
        builder.append("ws://")
                .append(request.getServerName())
                .append(":")
                .append(request.getServerPort())
                .append(request.getContextPath())
                .append("/");
        return builder.toString();
    }

 

posted @ 2021-10-08 17:13  yvioo  阅读(626)  评论(0编辑  收藏  举报