[英]Using ROSBridge Between Two Processes on the Same Computer
I have a C++ ROS node using ROSBridge to send the ROS Topics as JSON strings via TCP WebSocket over port 9090. On the same computer, I have a C# Unity program that needs to access the JSON and send some of its own. 我有一个C ++ ROS节点,使用ROSBridge通过9090端口通过TCP WebSocket将ROS Topics作为JSON字符串发送。在同一台计算机上,我有一个C#Unity程序,需要访问JSON并发送它自己的一些程序。 If I put this program on a different computer there is no problem--I can access port 9090 and see the JSON.
如果我将此程序放在另一台计算机上没有问题,那么我可以访问端口9090并查看JSON。 But if it is on the same computer as the ROSBridge Host, then there is a conflict with using the same port.
但是,如果它与ROSBridge主机位于同一台计算机上,则使用同一端口会有冲突。 So the two applications cannot communicate with each other on the same PC but they can on separate PCs.
因此,这两个应用程序不能在同一台PC上相互通信,但是可以在不同的PC上进行通信。
So what can I do? 那我该怎么办? Must the ports match and thus always conflict or maybe I can somehow make Process A send on 9090 but receive on 9091 and Process B just the opposite or something?
端口必须匹配并且总是冲突吗,或者我可以以某种方式使进程A在9090上发送但在9091与进程B上相反? Any other options?
还有其他选择吗? In essence, I'm trying to get Unity to participate in the ROS communications, but it does not have native support for that and thus the workaround with the ROSBridge JSON strings.
本质上,我正在尝试让Unity参与ROS通信,但它对此没有本地支持,因此没有使用ROSBridge JSON字符串的解决方法。
According to http://wiki.ros.org/rosbridge_suite/Tutorials/RunningRosbridge you can set the port that Rosbridge talks on in the .launch
file. 根据http://wiki.ros.org/rosbridge_suite/Tutorials/RunningRosbridge,您可以在
.launch
文件中设置Rosbridge所使用的端口。
If you are using the example rosbridge_websocket.launch
file, the second line of the file includes a port number in the form of <arg name="port" default="9090" />
. 如果您使用的是示例
rosbridge_websocket.launch
文件,则文件的第二行包含<arg name="port" default="9090" />
形式的端口号。 You can change 9090
to change the default port it uses. 您可以更改
9090
来更改其使用的默认端口。
According to the roslaunch
documentation at http://wiki.ros.org/roslaunch/Commandline%20Tools you can also pass arguments to roslaunch
on the command line: 根据http://wiki.ros.org/roslaunch/Commandline%20Tools上的
roslaunch
文档,您还可以在命令行roslaunch
参数传递给roslaunch
:
The rosbridge_websocket.launch
file sets the port from the argument "port", so if you run roslaunch like this it will use port 8080: rosbridge_websocket.launch
文件通过参数“ port”设置端口,因此,如果您这样运行roslaunch,它将使用端口8080:
roslaunch rosbridge_server rosbridge_websocket.launch port:=8080
You can see the full rosbridge_websocket.launch file at https://github.com/RobotWebTools/rosbridge_suite/blob/develop/rosbridge_server/launch/rosbridge_websocket.launch 您可以在https://github.com/RobotWebTools/rosbridge_suite/blob/develop/rosbridge_server/launch/rosbridge_websocket.launch上看到完整的rosbridge_websocket.launch文件。
Looking over that file for the line <param name="port" value="$(arg port)"/>
is how I know that it uses the "port" argument to set the port. 在该文件中查找行
<param name="port" value="$(arg port)"/>
就是我知道它使用“ port”参数设置端口的方式。
If you post your .launch
files I can give your more advice on how to edit them if this answer is not clear. 如果您发布
.launch
文件,如果此答案不清楚,我可以为您提供有关如何编辑它们的更多建议。
It sounds like my understanding about ports was lacking. 听起来我缺乏对端口的了解。 The host for the ROSBridge is being set up to use port 9090 so that anyone wishing to connect to it will request the host's port 9090 for the connection but will still use whatever port it desires on its own side.
ROSBridge的主机已设置为使用端口9090,因此,希望连接到该主机的任何人都将请求主机的端口9090进行连接,但仍将使用其自己需要的任何端口。 In both applications, I can state that the "Host" port is 9090 without conflict because the client application will still open a random other port for its own use to connect to the host port.
在这两个应用程序中,我都可以声明“主机”端口为9090,而不会发生冲突,因为客户端应用程序仍会打开一个随机的其他端口供自己连接到主机端口。 Therefore, the trouble I am experiencing is something other than "port sharing" since that is not what is happening.
因此,我遇到的麻烦不是“端口共享”,而是因为这不是正在发生的事情。 Only one is hosting on 9090.
9090上只有一台主机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.