Sockets, tasks and another stuffs

Hi,

well I'm learning every day new things about programming with orocos but I'm
having more doubts every day. I have implemented, following the structure that
Peter Soetens showed us in a previous mail about a task that open a socked
and listen to connections.

I have the same example running in a "normal" program and it simple works.
It's not a very special program, I have modified a typical example of network
programing.

With my orocos program, the problem that I have is that simple doesn't works.
The recv part doesn't wait. I have tested with timeout and without time out.
So, probably I'm doing something conceptually wrong.

Could someone help me a bit?

Regards,

Leo

Sockets, tasks and another stuffs

On Thursday 24 January 2008 12:36:33 Leopold Palomo-Avellaneda wrote:
> Hi,
>
> well I'm learning every day new things about programming with orocos but
> I'm having more doubts every day. I have implemented, following the
> structure that Peter Soetens showed us in a previous mail about a task that
> open a socked and listen to connections.
>
> I have the same example running in a "normal" program and it simple works.
> It's not a very special program, I have modified a typical example of
> network programing.
>
> With my orocos program, the problem that I have is that simple doesn't
> works. The recv part doesn't wait. I have tested with timeout and without
> time out. So, probably I'm doing something conceptually wrong.

Which target are you using ? gnulinux ?

'Orocos' does not change your network stack or functions. It's 'just' a
library creating some threads and providing some objects.

In your normal program, did you use threads or only the main() function ?

Peter

Sockets, tasks and another stuffs

A Dijous 24 Gener 2008, Peter Soetens va escriure:
> On Thursday 24 January 2008 12:36:33 Leopold Palomo-Avellaneda wrote:
> > Hi,
> >
> > well I'm learning every day new things about programming with orocos but
> > I'm having more doubts every day. I have implemented, following the
> > structure that Peter Soetens showed us in a previous mail about a task
> > that open a socked and listen to connections.
> >
> > I have the same example running in a "normal" program and it simple
> > works. It's not a very special program, I have modified a typical example
> > of network programing.
> >
> > With my orocos program, the problem that I have is that simple doesn't
> > works. The recv part doesn't wait. I have tested with timeout and without
> > time out. So, probably I'm doing something conceptually wrong.
>
> Which target are you using ? gnulinux ?

gnulinux

> 'Orocos' does not change your network stack or functions. It's 'just' a
> library creating some threads and providing some objects.
>
> In your normal program, did you use threads or only the main() function ?

No Peter, no. It's a very simple program. Probably I'm doing something stupid.

I have 2 classes derived from taskcontext: listener and control. The listener
class has this header:

######################################3

class listener : public RTT::TaskContext
{
WriteDataPort outPort;
public:
listener(std::string name);
protected:
bool startHook();
void stopHook() ;
void updateHook();
bool configureHook();
void cleanupHook();
void errorHook();
void warning();

private:
bool getDataFromChar(char *charData, NetData &sData);
int read_socket();
int udpSocket;
int port;
int status;
int size;
socklen_t clientLength;
struct sockaddr_in serverName;
struct sockaddr_in clientName;
bool error;
NetData data;
struct timeval timeout;
int num_errors;
char mesg[MAX_MESG_SIZE];

};

and the control :

class control : public RTT::TaskContext
{
ReadDataPort inpPort;
NetData data;
public:
control(std::string name);
protected:
bool startHook();
void stopHook() ;
void updateHook();
bool configureHook();
void cleanupHook();
void errorHook();
void warning();
};

###############################

the main has:

###############################

int ORO_main(int arc, char* argv[])
{
// Set log level more verbose than default,
// such that we can see output :
if ( Logger::log().getLogLevel() < Logger::Info ) {
Logger::log().setLogLevel( Logger::Info );
Logger::log() << Logger::Info << argv[0] << " manually raises LogLevel
to 'Info' (5). See also file 'orocos.log'."< }

listener listenerTask("Listener");
control controlTask("Control");

connectPeers( &listenerTask, &controlTask);
listenerTask.connectPorts( &controlTask );

// ... start the execution engine of a_task :
PeriodicActivity periodicControlTask(OS::HighestPriority, 0.004,
controlTask.engine() );
NonPeriodicActivity nonperiodiclistenerTask(ORO_SCHED_RT, 10,
listenerTask.engine() );

controlTask.start();
TaskBrowser browser( &controlTask );

browser.loop();

listenerTask.stop();
controlTask.stop();

return 0;
}

###################

then when I run, I make:

cd Listener
start

but:

- I have tested it showing the message of the timeout and i have hot be able
of connect.
- I have disable the timeout, and still not connect and not blocked as I was
expected.

I insist, I'm feel as a newbie with orocos and probably I'm doing something
wrong very obviously.

Leo

Sockets, tasks and another stuffs

On Thursday 24 January 2008 15:18:46 Leopold Palomo-Avellaneda wrote:
>
> No Peter, no. It's a very simple program. Probably I'm doing something
> stupid.
>
> I have 2 classes derived from taskcontext: listener and control. The
> listener class has this header:

If the program is this simple, could you just send over the header and cpp
file (in private) ? We once did socket communication inside the RTT to send
out timing information (a ThreadScope implementation) over a network, and
that worked in gnulinux and lxrt with RTT 1.0...

Peter

>
>
> ######################################3
>
> class listener : public RTT::TaskContext
> {
> WriteDataPort outPort;
> public:
> listener(std::string name);
> protected:
> bool startHook();
> void stopHook() ;
> void updateHook();
> bool configureHook();
> void cleanupHook();
> void errorHook();
> void warning();
>
> private:
> bool getDataFromChar(char *charData, NetData &sData);
> int read_socket();
> int udpSocket;
> int port;
> int status;
> int size;
> socklen_t clientLength;
> struct sockaddr_in serverName;
> struct sockaddr_in clientName;
> bool error;
> NetData data;
> struct timeval timeout;
> int num_errors;
> char mesg[MAX_MESG_SIZE];
>
> };
>
> and the control :
>
> class control : public RTT::TaskContext
> {
> ReadDataPort inpPort;
> NetData data;
> public:
> control(std::string name);
> protected:
> bool startHook();
> void stopHook() ;
> void updateHook();
> bool configureHook();
> void cleanupHook();
> void errorHook();
> void warning();
> };
>
> ###############################
>
> the main has:
>
>
> ###############################
>
> int ORO_main(int arc, char* argv[])
> {
> // Set log level more verbose than default,
> // such that we can see output :
> if ( Logger::log().getLogLevel() < Logger::Info ) {
> Logger::log().setLogLevel( Logger::Info );
> Logger::log() << Logger::Info << argv[0] << " manually raises
> LogLevel to 'Info' (5). See also file 'orocos.log'."< > }
>
> listener listenerTask("Listener");
> control controlTask("Control");
>
> connectPeers( &listenerTask, &controlTask);
> listenerTask.connectPorts( &controlTask );
>
> // ... start the execution engine of a_task :
> PeriodicActivity periodicControlTask(OS::HighestPriority, 0.004,
> controlTask.engine() );
> NonPeriodicActivity nonperiodiclistenerTask(ORO_SCHED_RT, 10,
> listenerTask.engine() );
>
> controlTask.start();
> TaskBrowser browser( &controlTask );
>
> browser.loop();
>
> listenerTask.stop();
> controlTask.stop();
>
> return 0;
> }
>
> ###################
>
>
> then when I run, I make:
>
> cd Listener
> start
>
> but:
>
> - I have tested it showing the message of the timeout and i have hot be
> able of connect.
> - I have disable the timeout, and still not connect and not blocked as I
> was expected.
>
> I insist, I'm feel as a newbie with orocos and probably I'm doing something
> wrong very obviously.
>
> Leo

try to use namespace RTT,

try to use namespace RTT, maybe work