Ask Your Question
0

Topic publishing via internet using web server

asked 2020-07-02 01:58:09 -0500

masa77 gravatar image

updated 2020-07-02 02:34:01 -0500

gvdhoorn gravatar image

I'd like to publish ros topics from remote PC using web server via internet network. I use roswww and rosbridge_server. In local network, it works. I mean, accessing "192.168.xxx.xxx:8085/ws/pub.html" from remote PC in the same local network succeed. I used chrome browser, and the script in the html file worked correctly. But via internet, same html doesn't work. I mean, accessing "(global IP address)/ws/pub.html" from remote PC in another network failed. The contents of the html file was showed correctly but ros.on connection in the script was failed. It seems establishing server and network setting (port mapping in internet router) are working, but there are any other factors to make ros topic publisher work correctly. Now I have no idea to solve or debug this problem (I'm just a beginner of ROS). Please give me some advices. The javascript script in the html is below:

if(!Talker){

    var Talker = {
        ros : null,
        name : "",
        init : function(){
            this.ros = new ROSLIB.Ros();
            this.ros.on('error', function(error) {
                document.getElementById('state').innerHTML = "Error";
            });
            this.ros.on('connection', function(error) {
                document.getElementById('state').innerHTML = "Connect";
            });
            this.ros.on('close', function(error) {
                document.getElementById('state').innerHTML = "Close";
            });
            this.ros.connect('ws://' + location.hostname + ':9090');
        },
        send : function(){
            if(document.getElementById("comment").value.length == 0) return;
            var comment = document.getElementById("comment").value;
            var pub = new ROSLIB.Topic({
                ros : this.ros,
                name : '/chatter',
                messageType : 'std_msgs/String'
            });

            var str = new ROSLIB.Message({data : comment});
            pub.publish(str);
        }
    }
    Talker.init();

    window.onload = function(){
    };
    window.onunload = function(){
        Talker.ros.close();
    };
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-06 22:24:38 -0500

masa77 gravatar image

It's solved.
The problem was in the code of " ros.connect('ws://' + location.hostname + ':9090'); ".
In this code, my web client issues websocket connection to port :9090. However since my client is in WAN and using http connection, this websocket connection is also sent to port :80 not :9090. Then I needed to make reverse proxy in the server side.
Eventually, I used Nginx for constructing reverse proxy to send "http connection" to :8085 and send "websocket connection" to :9090. After that, I found rosbridge has a bug of receiving websocket via reverse proxy websocket_external_port default setting.

After fixing those things, "Topic publishing via internet using web server" is working now.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-07-02 01:58:09 -0500

Seen: 545 times

Last updated: Jul 06 '20