Ask Your Question

create service on android

asked 2012-11-09 01:47:54 -0600

markkre gravatar image


I'm trying to create a service with rosjava on Android. However, I need to use an old rosjava version since I need the support for actionlib.

So, when I create the service server in my app, I can even see it with rxgraph on the linux machine running the roscore. However, as soon as i try to call the service via command line with "rosservice call /callme" (/callme is the name of the service) I receive following error messages:

Traceback (most recent call last): File "/opt/ros/electric/ros/bin/rosservice", line 46, in <module> rosservice.rosservicemain() File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 734, in rosservicemain _rosservice_cmd_call(argv) File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 586, in _rosservice_cmd_call service_class = get_service_class_by_name(service_name) File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 357, in get_service_class_by_name service_type = get_service_type(service_name) File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 141, in get_service_type return get_service_headers(service_name, service_uri).get('type', None) File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 113, in get_service_headers return, cStringIO.StringIO(), 2048) File "/opt/ros/electric/ros/core/roslib/src/roslib/", line 367, in read_ros_handshake_header raise ROSHandshakeException("connection from sender terminated before handshake header received. %s bytes were received. Please check sender for additional details."%b.tell()) connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.

The code is: package com.example.sandbox_ros;

import org.ros.internal.node.service.ServiceException;
import org.ros.internal.node.service.ServiceResponseBuilder;
import org.ros.namespace.GraphName;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.service.myMessages.onlyReturn;

import android.util.Log;

public class TestServiceServer implements NodeMain {

    private final String TAG = "TestServiceServer";

    public void onShutdown(Node arg0) {
        // TODO Auto-generated method stub


    public void onShutdownComplete(Node arg0) {
        // TODO Auto-generated method stub


    public void onStart(Node node) {

        /*ServiceServer<org.ros.message.std_msgs.Empty, org.ros.message.std_msgs.String> server = */
        node.newServiceServer("/callme", "myMessages/onlyReturn", new ServiceResponseBuilder<onlyReturn.Request, onlyReturn.Response>() {

            public onlyReturn.Response build(onlyReturn.Request request) throws ServiceException {

                Log.i(TAG, "request: " +;

                onlyReturn.Response response = new onlyReturn.Response();
       = "Thank you for calling! :)";

                Log.i(TAG, "I have been called!");

                return response;


    public GraphName getDefaultNodeName() {
        // TODO Auto-generated method stub
        return null;


and the node is created with:

NodeConfiguration configuration = NodeConfiguration.newPublic(androidhostIP, uriOfROSMachine);
Date date = new Date();
configuration.setNodeName("srs_ui_loc_start" + "_" + date.getTime());

TestServiceServer testNode = new TestServiceServer();

NodeMainExecutor runner = DefaultNodeMainExecutor.newDefault();

runner.execute(testNode, configuration);

I know, I'm using something old, but I though, maybe I'm not alone? :) Or maybe someone remembers that problem from former times?

edit retag flag offensive close merge delete


funny thing: I have implemented the add_two_ints_server on Android. When I run "rosrun rospy_tutorials add_two_ints_client 1 2" it works, I receive "1 + 2 = 3" :D So, it seems to work with python clients. I think I can live with that workaround :)

markkre gravatar image markkre  ( 2012-11-15 22:51:32 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2012-11-15 22:53:18 -0600

markkre gravatar image

Using a python ros service client instead of calling the server via "rosservice call /servicename parameters" command line works.

edit flag offensive delete link more

answered 2012-11-12 22:50:32 -0600

damonkohler gravatar image

This is an old bug that's fixed in newer versions of rosjava. I'm afraid you'll need to upgrade to get rid of it. The fix is non-trivial.

edit flag offensive delete link more


an upgrade means, i can't use actionlib anymore. No option for me.

markkre gravatar image markkre  ( 2012-11-15 20:45:45 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-11-09 01:47:54 -0600

Seen: 327 times

Last updated: Nov 15 '12