28 #include <sys/socket.h> 29 #include <netinet/in.h> 30 #include <sys/types.h> 65 _sock = ::socket(PF_INET, SOCK_STREAM, 0);
72 struct sockaddr_in localsocket;
73 struct sockaddr remote;
74 int adrlen =
sizeof(remote);
76 localsocket.sin_family = AF_INET;
77 localsocket.sin_port = htons(_port);
78 localsocket.sin_addr.s_addr = INADDR_ANY;
79 if( ::bind(_sock, (
struct sockaddr*)&localsocket,
sizeof(localsocket) ) < 0 )
85 #define TRY_OTHER_PORTS 87 #ifdef TRY_OTHER_PORTS 90 while( errno == EADDRINUSE && i < 5 && r < 0 )
92 localsocket.sin_port = htons(_port + i);
93 r = ::bind(_sock, (
struct sockaddr*)&localsocket,
sizeof(localsocket) );
101 if( errno == EADDRINUSE )
109 #ifdef TRY_OTHER_PORTS 114 if( ::
listen(_sock, 2) < 0 )
122 int socket = ::accept( _sock, &remote,
123 reinterpret_cast<socklen_t*>(&adrlen) );
131 _marshaller->
addConnection(
new Orocos::TCP::Socket(socket) );
138 :
Activity(10), _marshaller(marshaller)
182 int sock = ::socket(PF_INET, SOCK_STREAM, 0);
185 struct sockaddr_in socket;
186 socket.sin_family = AF_INET;
187 socket.sin_port = htons(_port);
188 socket.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
189 ::connect( sock, (
struct sockaddr*)&socket,
sizeof(socket) );
216 port_prop(
"port",
"port to listen/send to",3142)
bool addMarshaller(RTT::marsh::MarshallInterface *headerM, RTT::marsh::MarshallInterface *bodyM)
A component which writes data reports to a tcp/ip socket. It can serve different clients. It uses a ASCI-based protocol.
static void destroyInstance()
ORO_LIST_COMPONENT_TYPE(OCL::TcpReporting)
ListenThread(RTT::SocketMarshaller *marshaller, unsigned short port)
const RTT::PropertyBag * getReport()
RTT::SocketMarshaller * _marshaller
TcpReporting(std::string fr_name="ReportingComponent")
static ListenThread * _instance
Property< T > & addProperty(const std::string &name, T &attr)
static std::ostream & endl(std::ostream &__os)
A Component for periodically reporting Component Port contents to a human readable text format...
PropertyBag * properties()
RTT::Property< unsigned int > port_prop
static void createInstance(RTT::SocketMarshaller *marshaller, unsigned short port=3142)
void addConnection(OCL::TCP::Socket *os)
RTT::SocketMarshaller * fbody