YARP
Yet Another Robot Platform
os/simple_sender.cpp

This outputs some data to a port.Designed to be used with os/simple_receiver.cpp example.

/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#include <yarp/os/Port.h>
#include <yarp/os/Bottle.h>
#include <yarp/os/Time.h>
#include <stdio.h>
using namespace yarp::os;
int main() {
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
}
output.close();
return 0;
}
yarp::os::Port::close
void close() override
Stop port activity.
Definition: Port.cpp:356
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:72
yarp::os::Bottle::toString
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
Network.h
Port.h
main
int main(int argc, char *argv[])
Definition: yarpros.cpp:259
yarp::os::Port::open
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: Port.cpp:81
yarp::os::Port
Definition: Port.h:49
yarp::os::Bottle::addInt32
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:143
yarp::os::Bottle::addString
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition: Bottle.cpp:173
yarp::os::Port::write
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition: Port.cpp:429
yarp::os
Definition: AbstractCarrier.h:17
yarp::os::Network
Definition: Network.h:781
yarp
Definition: numeric.h:47
Time.h
yarp::os::Time::delay
void delay(double seconds)
Wait for a certain number of seconds.
Definition: Time.cpp:114
Bottle.h