ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

roslibjs auto disconnected when calling any function

asked 2018-11-16 21:13:01 -0600

kdorsel gravatar image

updated 2018-11-16 21:15:18 -0600

I'm running melodic on macOS 10.13.6.

I got the latest rosauth and rosbridge_suite from git and have them in my catkin_ws and build ok. I also have my test project which launches the rosbridge server and a simple python web server for the webpage.

Here's the javascript snippet that is used to connect:

$(function() {
  var ros = new ROSLIB.Ros({
    url : 'ws://127.0.0.1:9090'
  });
  window.ros = ros;

  ros.on('connection', function() {
    console.log('Connected to websocket server.');
    $('#status span').html('Connected');
  });

  ros.on('error', function(error) {
    console.log('Error connecting to websocket server: ', error);
    $('#status span').html('Error');
  });

  ros.on('close', function() {
    console.log('Connection to websocket server closed.');
    $('#status span').html('Disconnected');
  });

And here's the console output:

Connected to websocket server.
ros.getNodes(function(n){console.log(n)});
undefined
main.js:18 Connection to websocket server closed.
ros.connect('ws://127.0.0.1:9090')
undefined
main.js:8 Connected to websocket server.
ros
d {socket: WebSocket, idCounter: 1, isConnected: true, transportLibrary: "websocket", transportOptions: {…}, …}event: "connection"groovyCompatibility: trueidCounter: 1isConnected: truesocket: WebSocket {url: "ws://127.0.0.1:9090/", readyState: 1, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}transportLibrary: "websocket"transportOptions: {}_conf: {maxListeners: 0}_events: {maxListeners: 0, connection: ƒ, error: ƒ, close: ƒ, call_service:/rosapi/nodes:1: ƒ}__proto__: g
ros.getNodes(function(n){console.log(n)});
undefined
main.js:18 Connection to websocket server closed.
ros
d {socket: WebSocket, idCounter: 2, isConnected: false, transportLibrary: "websocket", transportOptions: {…}, …}event: "close"groovyCompatibility: trueidCounter: 2isConnected: falsesocket: WebSocket {url: "ws://127.0.0.1:9090/", readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}transportLibrary: "websocket"transportOptions: {}_conf: {maxListeners: 0}_events: {maxListeners: 0, connection: ƒ, error: ƒ, close: ƒ, call_service:/rosapi/nodes:1: ƒ, …}__proto__: g

Here't the output from the terminal window

[INFO] [1542421699.375919]: Serving at 127.0.0.1:8080
registered capabilities (classes):
 - rosbridge_library.capabilities.call_service.CallService
 - rosbridge_library.capabilities.advertise.Advertise
 - rosbridge_library.capabilities.publish.Publish
 - rosbridge_library.capabilities.subscribe.Subscribe
 - <class 'rosbridge_library.capabilities.defragmentation.Defragment'>
 - rosbridge_library.capabilities.advertise_service.AdvertiseService
 - rosbridge_library.capabilities.service_response.ServiceResponse
 - rosbridge_library.capabilities.unadvertise_service.UnadvertiseService
[INFO] [1542421699.610645]: Rosbridge WebSocket server started on port 9090
127.0.0.1 - - [16/Nov/2018 21:28:37] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 21:28:37] "GET /main.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 21:28:38] code 404, message File not found
127.0.0.1 - - [16/Nov/2018 21:28:38] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [16/Nov/2018 21:29:25] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 21:33:34] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov/2018 21:33:34] "GET /main.js HTTP/1.1" 200 -
[INFO] [1542422015.325308]: Client connected.  1 clients total.
[INFO] [1542422020.249735]: Client disconnected. 0 clients total.
127.0.0.1 - - [16/Nov/2018 21:34:18] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Nov ...
(more)
edit retag flag offensive close merge delete

Comments

1

Am experiencing this same issue. Have you found any resolution?

dtf gravatar image dtf  ( 2018-12-05 00:50:33 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-06-20 01:04:56 -0600

pROScription gravatar image

If you're using rosauth with rosbridgeyou'll need to authenticate after connection, otherwise the server will close the connection. See http://robotwebtools.org/jsdoc/roslib...

authenticate(mac, client, dest, rand, t, level, end)
Sends an authorization request to the server.
Parameters:
Name    Type    Description
mac         MAC (hash) string given by the trusted source.
client      IP of the client.
dest        IP of the destination.
rand        Random string given by the trusted source.
t       Time of the authorization request.
level       User level as a string given by the client.
end         End time of the client's session.
edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2018-11-16 21:13:01 -0600

Seen: 1,378 times

Last updated: Jun 20 '19