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

Is there any actual difference between a topic and a service?

asked 2017-01-25 01:34:08 -0500

sam26 gravatar image

updated 2017-01-25 02:48:34 -0500

gvdhoorn gravatar image

The above link quotes that:

Establishing a topic connection: Putting it all together, the sequence by which two nodes begin exchanging messages is:

  1. Subscriber starts. It reads its command-line remapping arguments to resolve which topic name it will use. (Remapping Arguments)
  2. Publisher starts. It reads its command-line remapping arguments to resolve which topic name it will use. (Remapping Arguments)
  3. Subscriber registers with the Master. (XMLRPC)
  4. Publisher registers with the Master. (XMLRPC)
  5. Master informs Subscriber of new Publisher. (XMLRPC)
  6. Subscriber contacts Publisher to request a topic connection and negotiate the transport protocol. (XMLRPC)
  7. Publisher sends Subscriber the settings for the selected transport protocol. (XMLRPC)
  8. Subscriber connects to Publisher using the selected transport protocol. (TCPROS, etc...)

In the above mentioned steps , the subscriber is requesting for the connection first and then the publisher is sending the settings for the protocol . So isn't it a two way here in topics as well . Where does the exact difference between a topic and a service comes from ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-25 02:16:05 -0500

mgruhler gravatar image

See the wiki Concept page

Whereas Pub/Sub is many-to-many, one-way transport, Services are one-to-one, two-way transport providing the Request/Reply pattern.

The page you are refering to shows how the actual connection is set up. Basically, this describes that each publisher/subscriber has to register at the master, but the actual topic transmission is happening between the two directly. However, any number of publisher/subscribers to one topic can exist. However, you can only have one service server (i.e. service provider) for one type (name) of a service.

edit flag offensive delete link more


So , does it mean that establishing a connection can have either way communication depending on transport protocol selected,while during the actual transfer of data , topics can only send data from publisher to subscriber and services need a request from the subscriber first ?

sam26 gravatar image sam26  ( 2017-01-25 03:11:37 -0500 )edit

The "service" is a procedure call and is synchronous. The caller waits from the response. The "topic" is asynchronous. The publisher of a message on a topic has no guarantee when the subscriber will process the message.

suforeman gravatar image suforeman  ( 2017-01-25 04:24:58 -0500 )edit

Question Tools

1 follower


Asked: 2017-01-25 01:34:08 -0500

Seen: 6,410 times

Last updated: Jan 25 '17