[ros-users] [Discourse.ros.org] [ROS Projects] ROS# on github.com/siemens/ros-sharp
Martin Bischoff
ros.discourse at gmail.com
Wed Dec 13 10:43:32 UTC 2017
## Code Example ##
A simple Publisher/Subscriber Example:
```cs
using System;
using RosSharp.RosBridgeClient;
// commands on ROS system:
// roscore
// rostopic echo /talker
// rostopic pub /listener std_msgs/String "World!"
// roslaunch rosbridge_server rosrbridge_websocket.launch
public class HelloWorld
{
public static void Main(string[] args)
{
RosSocket rosSocket = new RosSocket("ws://192.168.0.101:9090");
// Publication:
int publication_id = rosSocket.Advertize("/talker", "std_msgs/String");
StandardString message = new StandardString();
message.data = "Hello!";
rosSocket.Publish(publication_id, message);
// Subscription Example:
int subscription_id = rosSocket.Subscribe("/listener", "std_msgs/String", subscriptionHandler);
Console.WriteLine("Press any key to close...");
Console.ReadKey(true);
rosSocket.Close();
}
private static void subscriptionHandler(Message message)
{
StandardString standardString = (StandardString)message;
Console.WriteLine(standardString.data);
}
}
```
---
[Visit Topic](https://discourse.ros.org/t/ros-on-github-com-siemens-ros-sharp/3405/2) or reply to this email to respond.
More information about the ros-users
mailing list