【问题标题】:How do I find out the websocket url of my server?如何找出我的服务器的 websocket url?
【发布时间】:2016-04-15 23:44:06
【问题描述】:

我正在尝试在 Openshift 上托管一个 Web 应用程序。我正在使用一个处理所有连接的 websocket。但是,我不确定要为我的套接字 url 输入什么值。我有一个 .js 文件,内容如下:

...
// socket connection url and port
var socket_url = '192.168.8.102';
var port = '8080';

$(document).ready(function() {

    $("#form_submit, #form_send_message").submit(function(e) {
        e.preventDefault();
        join();
    });
});

var webSocket;

/**
 * Connecting to socket
 */
function join() {
    // Checking person name
    if ($('#input_name').val().trim().length <= 0) {
        alert('Enter your name');
    } else {
        name = $('#input_name').val().trim();

        $('#prompt_name_container').fadeOut(1000, function() {
            // opening socket connection
            openSocket();
        });
    }

    return false;
}

/**
 * Will open the socket connection
 */
function openSocket() {
    // Ensures only one connection is open at a time
    if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) {
        return;
    }

    // Create a new instance of the websocket
    webSocket = new WebSocket("ws://" + socket_url + ":" + port
            + "/WebMobileGroupChatServer/chat?name=" + name);

....

当我在本地测试它时,它使用我的本地 IP 地址 192.168.8.102 作为 socket_url 可以完美运行。但是,如果我要将我的程序用于在线托管,我应该输入什么值的 socket_url 呢?我的域名是http://jbosslew-weihao.rhcloud.com/

当我使用tomcat apache服务器在本地测试时,域名是 http://192.168.8.102:8080/WebMobileGroupChatServer/

如何在 openshift 上找到我的服务器的套接字 url?

【问题讨论】:

    标签: java tomcat websocket server openshift


    【解决方案1】:

    根据https://developers.openshift.com/en/managing-port-binding-routing.html,您需要将其绑定到端口8000以进行常规访问或绑定到端口8443以进行安全访问

    所以你的 websockets url 将是以下之一:

    ws://app-domain.rhcloud.com:8000/路径
    wss://app-domain.rhcloud.com:8443/path

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-12
      • 2018-08-03
      • 1970-01-01
      • 2011-07-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多