Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client connection mode using the unused --address CLI argument #132

Merged
merged 2 commits into from
Feb 7, 2020

Conversation

smartin015
Copy link
Contributor

I have a setup with a internal (local) ROS network and an external (master) websocket server. The external server has a public websocket address, but the ROS network is not exposed.

This PR allows the web bridge to be a websocket client that connects to the external server - requests can be issued by the server and proxied into the local network the same way a regular client would connect to the ros2-web-bridge as before. The --address arg was apparently totally unused, so I co-opted that to open a client connection instead of a server connection.

In the new test I added, there's a setTimeout I'm not particularly proud of. Without this timeout, the test would fail every 4-5 runs due to a race condition in the WS library - with the timeout, the test passes ~50x in a row. I tried other options including process.nexttick to no avail... I'm open to suggestions on a better way.

Copy link
Member

@minggangw minggangw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this useful feature and I also noticed that ROS1 bridge has a similar idea of it. I am going to merge the PR, and would you please add the usage of this feature at the Run Examples section of README in a following patch, thanks!

// new connections prevents us from sending messages
// immediately after startup
// More details at https://github.com/websockets/ws/issues/1393
setTimeout(() => ws.send(JSON.stringify(msg)), 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Ok to add the timeout here because it's not event-driven for the establishment of a new connection.

@minggangw minggangw merged commit e4fd9b5 into RobotWebTools:develop Feb 7, 2020
minggangw pushed a commit that referenced this pull request Mar 22, 2020
This is a followup from a comment in #132 that instructs on the usage of client mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants