title: How to reply a D-Bus message
body: <p>I got the D-Bus server.c and client.c code, and made some modification.
  I want the result that when type for example "hi" from client.c
  server will print "receive message hi", and reply "reply_content!!!!!!" to client.c</p>
  
  <p>But it seems that now client.c cannot get the reply message.
  Anyone have the idea?</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>"server.c"
  /* server.c */
  
  #include &lt;dbus/dbus.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  static DBusHandlerResult
  filter_func(DBusConnection *connection, DBusMessage *message, void *usr_data)
  {
      DBusMessage *reply;
      dbus_bool_t handled = false;
      char *word = NULL;
      DBusError dberr;
  
      dbus_error_init(&amp;dberr);
      dbus_message_get_args(message, &amp;dberr, DBUS_TYPE_STRING, &amp;word, DBUS_TYPE_INVALID);
      printf("receive message: %s\n", word);
      handled = true;
  
      reply = dbus_message_new_method_return(message);
      char * reply_content = "reply_content!!!!!!";
  
      dbus_message_append_args(reply, DBUS_TYPE_STRING, &amp;reply_content, DBUS_TYPE_INVALID);
  
      dbus_connection_send(connection, reply, NULL);
      dbus_connection_flush(connection);
      dbus_message_unref(reply);
  
      return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
  }
  
  int main(int argc, char *argv[])
  {
      DBusError dberr;
      DBusConnection *dbconn;
  
      dbus_error_init(&amp;dberr);
      dbconn = dbus_bus_get(DBUS_BUS_SESSION, &amp;dberr);
  
      if (!dbus_connection_add_filter(dbconn, filter_func, NULL, NULL)) {
          return -1;
      }
  
      dbus_bus_add_match(dbconn, "type='signal',interface='client.signal.Type'", &amp;dberr);
  
      while(dbus_connection_read_write_dispatch(dbconn, -1)) {
          /* loop */
      }
      return 0;
  }
  </code></pre>
  
  <p>Here is client.c</p>
  
  <pre><code>#include &lt;dbus/dbus.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  static DBusHandlerResult
  filter_func(DBusConnection *connection, DBusMessage *message, void *usr_data)
  {
      dbus_bool_t handled = false;
      char *word = NULL;
      DBusError dberr;
  
      dbus_error_init(&amp;dberr);
      dbus_message_get_args(message, &amp;dberr, DBUS_TYPE_STRING, &amp;word, DBUS_TYPE_INVALID);
  
      printf("receive message %s\n", word);
      handled = true;
  
      return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
  }
  
  
  int db_send(DBusConnection *dbconn)
  {
      DBusMessage *dbmsg;
      char *word = (char *)malloc(sizeof(char));
      int i;
  
      dbmsg = dbus_message_new_signal("/client/signal/Object", "client.signal.Type", "Test");
  
      scanf("%s", word);
  
      if (!dbus_message_append_args(dbmsg, DBUS_TYPE_STRING, &amp;word, DBUS_TYPE_INVALID)) {
      return -1;
      }
  
      if (!dbus_connection_send(dbconn, dbmsg, NULL)) {
          return -1;
      }
      dbus_connection_flush(dbconn);
      printf("send message %s\n", word);
  
      dbus_message_unref(dbmsg);
      return 0;
  }
  
  int main(int argc, char *argv[])
  {
      DBusError dberr;
      DBusConnection *dbconn;
  
      dbus_error_init(&amp;dberr);
  
      dbconn = dbus_bus_get(DBUS_BUS_SESSION, &amp;dberr);
      if (!dbus_connection_add_filter(dbconn, filter_func, NULL, NULL)) {
          return -1;
      }
  
      db_send(dbconn);
  
      while(dbus_connection_read_write_dispatch(dbconn, -1)) {
          db_send(dbconn);
      }
      dbus_connection_unref(dbconn);
  
      return 0;
  }
  </code></pre>