Esempio n. 1
0
Bottle NameServer::botify(const Contact& address) {
    Bottle result;
    if (address.isValid()) {
        Bottle bname;
        bname.addString("name");
        bname.addString(address.getRegName().c_str());
        Bottle bip;
        bip.addString("ip");
        bip.addString(address.getHost().c_str());
        Bottle bnum;
        bnum.addString("port_number");
        bnum.addInt32(address.getPort());
        Bottle bcarrier;
        bcarrier.addString("carrier");
        bcarrier.addString(address.getCarrier().c_str());

        result.addString("port");
        result.addList() = bname;
        result.addList() = bip;
        result.addList() = bnum;
        result.addList() = bcarrier;
    } else {
        Bottle bstate;
        bstate.addString("error");
        bstate.addInt32(-2);
        bstate.addString("port not known");
        result.addString("port");
        result.addList() = bstate;
    }
    return result;
}
Esempio n. 2
0
    void requestTopic(NodeArgs& na)
    {
        std::string topic = na.args.get(0).asString();
        topic = fromRosName(topic);
        std::vector<Contact> contacts = query(topic, "+");
        if (contacts.size() < 1) {
            na.fail("Cannot find topic");
            return;
        }
        for (std::vector<Contact>::iterator it = contacts.begin(); it != contacts.end(); ++it) {
            Contact &c = *it;

            if (!c.isValid()) {
                continue;
            }
            Value v;
            Bottle* lst = v.asList();
            lst->addString("TCPROS");
            lst->addString(c.getHost());
            lst->addInt32(c.getPort());
            na.reply = v;
            na.success();
            return;
        }
        na.fail("Cannot find topic");
    }
Esempio n. 3
0
int main(int argc, char *argv[]) {
    if (argc<3) {
        fprintf(stderr, "Please supply (1) a port name for the client\n");
        fprintf(stderr, "              (2) a port name for the server\n");
        return 1;
    }

    Network yarp;
    const char *client_name = argv[1];
    const char *server_name = argv[2];

    RpcClient port;
    port.open(client_name);

    int ct = 0;
    while (true) {
	if (port.getOutputCount()==0) {
	  printf("Trying to connect to %s\n", server_name);
	  yarp.connect(client_name,server_name);
	} else {
	  Bottle cmd;
	  cmd.addString("COUNT");
	  cmd.addInt32(ct);
	  ct++;
	  printf("Sending message... %s\n", cmd.toString().c_str());
	  Bottle response;
	  port.write(cmd,response);
	  printf("Got response: %s\n", response.toString().c_str());
	}
	Time::delay(1);
    }
}
 virtual void run() {
     for (int i=0; i<R; i++) {
         Bottle b;
         b.addString(p.getName());
         b.addInt32(i);
         printf("Writing %s\n", b.toString().c_str());
         p.write(b);
         Time::delay(3);
     }
 }
Esempio n. 5
0
int main() {
    Network yarp;
    Port output;
    output.open("/sender");
    int top = 100;
    for (int i=1; i<=top; i++) {
        // prepare a message
        Bottle bot; 
        bot.addString("testing");
        bot.addInt32(i);
        bot.addString("of");
        bot.addInt32(top);
        // send the message
        output.write(bot);
        printf("Sent message: %s\n", bot.toString().c_str());
        // wait a while
        Time::delay(1);
    }
    output.close();
    return 0;
}
Esempio n. 6
0
bool yarp::os::Node::Helper::read(ConnectionReader& reader)
{
    if (!reader.isValid()) {
        return false;
    }
    NodeArgs na;
    na.request.read(reader);
    //printf("NODE API for %s received %s\n",
    //name.c_str(),
    //na.request.toString().c_str());
    std::string key = na.request.get(0).asString();
    na.args = na.request.tail().tail();
    if (key=="getBusStats") {
        getBusStats(na);
    } else if (key=="getBusInfo") {
        getBusInfo(na);
    } else if (key=="getMasterUri") {
        getMasterUri(na);
    } else if (key=="shutdown") {
        shutdown(na);
    } else if (key=="getPid") {
        getPid(na);
    } else if (key=="getSubscriptions") {
        getSubscriptions(na);
    } else if (key=="getPublications") {
        getPublications(na);
    } else if (key=="paramUpdate") {
        paramUpdate(na);
    } else if (key=="publisherUpdate") {
        publisherUpdate(na);
    } else if (key=="requestTopic") {
        requestTopic(na);
    } else {
        na.error("I have no idea what you are talking about");
    }
    if (na.should_drop) {
        reader.requestDrop(); // ROS likes to close down.
    }
    if (reader.getWriter()) {
        Bottle full;
        full.addInt32(na.code);
        full.addString(na.msg);
        full.add(na.reply);
        //printf("NODE %s <<< %s\n",
        //name.c_str(),
        //full.toString().c_str());
        full.write(*reader.getWriter());
    }
    return true;
}
Esempio n. 7
0
    void testBackground() {
        report(0,"background transmission check...");

        expectation = "";
        receives = 0;

        Contact write = NetworkBase::registerContact(Contact("/write", "tcp", "127.0.0.1", safePort()));
        Contact read = NetworkBase::registerContact(Contact("/read", "tcp", "127.0.0.1", safePort()+1));
        Contact fake("tcp", "127.0.0.1", safePort()+2);

        checkEqual(NetworkBase::queryName("/write").isValid(),true,"name server sanity");
        checkEqual(NetworkBase::queryName("/read").isValid(),true,"name server sanity");

        PortCore sender;

        sender.setWaitBeforeSend(false);
        sender.setWaitAfterSend(false);

        PortCore receiver;
        receiver.setReadHandler(*this);
        sender.listen(write);
        receiver.listen(read);
        sender.start();
        receiver.start();
        //Time::delay(1);
        Bottle bot;
        bot.addInt32(0);
        bot.addString("Hello world");
        report(0,"sending bottle, should received nothing");
        expectation = "";
        sender.send(bot);
        Time::delay(0.3);
        checkEqual(receives,0,"nothing received");
        NetworkBase::connect("/write", "/read");
        Time::delay(0.3);
        report(0,"sending bottle, should receive it this time");
        expectation = bot.toString();
        sender.send(bot);
        for (int i=0; i<1000; i++) {
            if (receives==1) break;
            Time::delay(0.3);
        }
        checkEqual(receives,1,"something received");
        sender.close();
        receiver.close();
    }
Esempio n. 8
0
int main() {
    Network yarp;
    
    int ct = 0;
    Port p;            // Create a port.
    p.open("/out");    // Give it a name on the network.
    while (true) {
        Bottle b;        // Make a place to store things.
        b.clear();
        b.addString("hello");
        b.addString("world");
        b.addInt32(ct);
        ct++;
        p.write(b);      // Send the data.
        printf("Sent %s\n", b.toString().c_str());
        Time::delay(1);
    }

    return 0;
}