Re: [nox-dev] Error in send a string using messenger component

2011-06-25 Thread Ricardo Bennesby
Hi. Thanks for reply, KK.

I am using the struct messenger_msg of messenger component:

  *struct messenger_msg
  {
uint16_t length;
uint8_t type;
string body;
  } __attribute__ ((packed));*

So, I declare and set the fields in my component:

* messenger_msg mymsg;
 mymsg.type = 0x0A;
 mymsg.body.append(Test);
 mymsg.length = (sizeof(messenger_msg));*

And the other part of the client (using socket):

*  int Mysocket, numbytes;
  char buf[MAXDATASIZE];
  struct hostent *he;
  struct sockaddr_in seu_endereco;

  if ((he=gethostbyname(localhost)) == NULL)   /* send host info */
  {
  herror(gethostbyname);
  exit(1);
  }

  seu_endereco.sin_family = AF_INET;
  seu_endereco.sin_port = htons(PORTA);
  seu_endereco.sin_addr = *((struct in_addr *)he-h_addr);
  bzero((seu_endereco.sin_zero), 8);

  if (send(Mysocket, mymsg, mymsg.length, 0) == -1) {
  perror(send);
  close(Mysocket);
  exit(0);
  }*

Where PORTA==2603;

But when I run it, the server client (messenger) prints:

00077|messenger_core|DBG:Copy 8 bytes to message
00078|messenger|DBG:Check message completeness 512 (expected 512)
00079|messenger_core|DBG:Received packet of length 512
00080|messenger|DBG:Message posted as Msg_event
00081|messenger|DBG:Received packet of length 512
00082|messenger_core|DBG:Copy 2 bytes to message
00083|messenger|DBG:Check message completeness 2 (expected 62559)
00084|messenger_core|DBG:Copy 502 bytes to message
00085|messenger|DBG:Check message completeness 504 (expected 62559)
00086|messenger|DBG:me.msg-length: 512 and sizeof(messenger_msg)+1: 9
00087|messenger|DBG:Received string ��Q�

The string Test is not printed. It shows ��Q� instead. What am I doing
wrong? Is it the length of the message that I am setting doing *mymsg.length
= (sizeof(messenger_msg))*; ? Or in the way I am using socket send function
in client (*send(Mysocket, mymsg, mymsg.length, 0)*) ?

Thanks for help.

Best Regards.

2011/6/18 kk yap yap...@stanford.edu

 Hi Ricardo,

 You might want to add a length and type in front of the string.  :)

 Regards
 KK

 On 18 June 2011 14:46, Ricardo Bennesby ricardo.benne...@gmail.com
 wrote:
  Hi.
 
  I am writing component in C++ that uses messenger component.
 
  I have a client function that send a string to the own component. As
  follows:
 
void comp::sendMessageOtherAs(){
  ClientSocket theSocket (localhost, 2603 );
  string request;
  request = Test;
  theSocket  request  \n;
  lg.dbg(Echo sent);
}
 
  The server part is did by messenger component, calling the handle_message
  function;
 
  But the result, when the handle_message is invoked is:
 
  00108|messenger_core|DBG:Starting connection with idleInterval 0
  00109|messenger_core|DBG:Received packet of length 0
  00110|messenger|DBG:Message posted as Msg_event
  00111|messenger_core|DBG:TCP socket connection accepted
  00112|messenger_core|DBG:Copy 2 bytes to message
  00113|messenger|DBG:Check message completeness 2 (expected 21349)
  00114|messenger_core|DBG:Copy 31 bytes to message
  00115|messenger|DBG:Check message completeness 33 (expected 21349)
  00116|messenger_core|DBG:Received packet of length 3
  00117|messenger_core|DBG:Received disconnection request
  00118|messenger|DBG:Message posted as Msg_event
  00119|messenger_core|DBG:socket closed
 
  And the handler messenger has the code:
 
  switch (me.msg-type)
  {
  case MSG_DISCONNECT:
return STOP;
break;
  case MSG_ECHO:
VLOG_DBG(lg, Got echo request);
reply_echo(me);
return STOP;
break;
  case MSG_ECHO_RESPONSE:
VLOG_DBG(lg, Echo reply received);
return STOP;
break;
  case MSG_NOX_STR_CMD:
char mstring[ntohs(me.msg-length)-sizeof(messenger_msg)+1];
memcpy(mstring, me.msg-body,
  ntohs(me.msg-length)-sizeof(messenger_msg));
mstring[ntohs(me.msg-length)-sizeof(messenger_msg)] = '\0';
VLOG_DBG(lg, Received string %s, mstring);
break;
  }
 
  Shouldn't the message be of MSG_NOX_STR_CMD type and prints the string
 sent?
  Or the way I am sending the string is wrong?
 
  Sorry if I did'n made me clear.
  Thanks for help.
  Regards.
 
  --
  Ricardo Bennesby da Silva
  Ciência da Computação - UFAM
  LabCIA - Laboratório de Computação Inteligente e Autônoma
 
 
  ___
  nox-dev mailing list
  nox-dev@noxrepo.org
  http://noxrepo.org/mailman/listinfo/nox-dev
 
 




-- 
Ricardo Bennesby da Silva
Ciência da Computação - UFAM
LabCIA - Laboratório de Computação Inteligente e Autônoma
___
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev


Re: [nox-dev] Error in send a string using messenger component

2011-06-25 Thread kk yap
Hi Ricardo,

You might want to take a closer look here
http://noxrepo.org/~yapkke/doc/classvigil_1_1messenger.html
http://noxrepo.org/~yapkke/doc/structvigil_1_1messenger__msg.html

The struct messenger_msg is defined in messenger.hh as (and not what
you presented in the email).

  struct messenger_msg
  {
/** Length of message, including this header.
 */
uint16_t length;
/** Type of message, as defined in \ref msg_type.
 */
uint8_t type;
/** Reference to body of message.
 */
uint8_t body[0];
  } __attribute__ ((packed));

Your packet length does seems way off to me at 512.  The packet sent
is not conforming to the expectation.

Hope this helps.

Regards
KK

On 25 June 2011 13:26, Ricardo Bennesby ricardo.benne...@gmail.com wrote:
 Hi. Thanks for reply, KK.

 I am using the struct messenger_msg of messenger component:

   struct messenger_msg
   {
     uint16_t length;
     uint8_t type;
     string body;
   } __attribute__ ((packed));

 So, I declare and set the fields in my component:

  messenger_msg mymsg;
  mymsg.type = 0x0A;
  mymsg.body.append(Test);
  mymsg.length = (sizeof(messenger_msg));

 And the other part of the client (using socket):

   int Mysocket, numbytes;
       char buf[MAXDATASIZE];
       struct hostent *he;
       struct sockaddr_in seu_endereco;

       if ((he=gethostbyname(localhost)) == NULL)   /* send host info */
       {
           herror(gethostbyname);
           exit(1);
       }

       seu_endereco.sin_family = AF_INET;
       seu_endereco.sin_port = htons(PORTA);
       seu_endereco.sin_addr = *((struct in_addr *)he-h_addr);
       bzero((seu_endereco.sin_zero), 8);

       if (send(Mysocket, mymsg, mymsg.length, 0) == -1) {
           perror(send);
           close(Mysocket);
           exit(0);
       }

 Where PORTA==2603;

 But when I run it, the server client (messenger) prints:

 00077|messenger_core|DBG:Copy 8 bytes to message
 00078|messenger|DBG:Check message completeness 512 (expected 512)
 00079|messenger_core|DBG:Received packet of length 512
 00080|messenger|DBG:Message posted as Msg_event
 00081|messenger|DBG:Received packet of length 512
 00082|messenger_core|DBG:Copy 2 bytes to message
 00083|messenger|DBG:Check message completeness 2 (expected 62559)
 00084|messenger_core|DBG:Copy 502 bytes to message
 00085|messenger|DBG:Check message completeness 504 (expected 62559)
 00086|messenger|DBG:me.msg-length: 512 and sizeof(messenger_msg)+1: 9
 00087|messenger|DBG:Received string ��Q�

 The string Test is not printed. It shows ��Q� instead. What am I doing
 wrong? Is it the length of the message that I am setting doing mymsg.length
 = (sizeof(messenger_msg)); ? Or in the way I am using socket send function
 in client (send(Mysocket, mymsg, mymsg.length, 0)) ?

 Thanks for help.

 Best Regards.

 2011/6/18 kk yap yap...@stanford.edu

 Hi Ricardo,

 You might want to add a length and type in front of the string.  :)

 Regards
 KK

 On 18 June 2011 14:46, Ricardo Bennesby ricardo.benne...@gmail.com
 wrote:
  Hi.
 
  I am writing component in C++ that uses messenger component.
 
  I have a client function that send a string to the own component. As
  follows:
 
    void comp::sendMessageOtherAs(){
      ClientSocket theSocket (localhost, 2603 );
      string request;
      request = Test;
      theSocket  request  \n;
      lg.dbg(Echo sent);
    }
 
  The server part is did by messenger component, calling the
  handle_message
  function;
 
  But the result, when the handle_message is invoked is:
 
  00108|messenger_core|DBG:Starting connection with idleInterval 0
  00109|messenger_core|DBG:Received packet of length 0
  00110|messenger|DBG:Message posted as Msg_event
  00111|messenger_core|DBG:TCP socket connection accepted
  00112|messenger_core|DBG:Copy 2 bytes to message
  00113|messenger|DBG:Check message completeness 2 (expected 21349)
  00114|messenger_core|DBG:Copy 31 bytes to message
  00115|messenger|DBG:Check message completeness 33 (expected 21349)
  00116|messenger_core|DBG:Received packet of length 3
  00117|messenger_core|DBG:Received disconnection request
  00118|messenger|DBG:Message posted as Msg_event
  00119|messenger_core|DBG:socket closed
 
  And the handler messenger has the code:
 
  switch (me.msg-type)
      {
      case MSG_DISCONNECT:
    return STOP;
    break;
      case MSG_ECHO:
    VLOG_DBG(lg, Got echo request);
    reply_echo(me);
    return STOP;
    break;
      case MSG_ECHO_RESPONSE:
    VLOG_DBG(lg, Echo reply received);
    return STOP;
    break;
      case MSG_NOX_STR_CMD:
    char mstring[ntohs(me.msg-length)-sizeof(messenger_msg)+1];
    memcpy(mstring, me.msg-body,
  ntohs(me.msg-length)-sizeof(messenger_msg));
    mstring[ntohs(me.msg-length)-sizeof(messenger_msg)] = '\0';
    VLOG_DBG(lg, Received string %s, mstring);
    break;
      }
 
  Shouldn't the message be of MSG_NOX_STR_CMD type and prints the 

Re: [nox-dev] Error in send a string using messenger component

2011-06-25 Thread Ricardo Bennesby
Hi KK.

I will take a look on it.

Thank you very much.

Regards.

2011/6/25 kk yap yap...@stanford.edu

 Hi Ricardo,

 You might want to take a closer look here
 http://noxrepo.org/~yapkke/doc/classvigil_1_1messenger.html
 http://noxrepo.org/~yapkke/doc/structvigil_1_1messenger__msg.html

 The struct messenger_msg is defined in messenger.hh as (and not what
 you presented in the email).

  struct messenger_msg
  {
/** Length of message, including this header.
 */
uint16_t length;
/** Type of message, as defined in \ref msg_type.
 */
uint8_t type;
/** Reference to body of message.
 */
uint8_t body[0];
  } __attribute__ ((packed));

 Your packet length does seems way off to me at 512.  The packet sent
 is not conforming to the expectation.

 Hope this helps.

 Regards
 KK

 On 25 June 2011 13:26, Ricardo Bennesby ricardo.benne...@gmail.com
 wrote:
  Hi. Thanks for reply, KK.
 
  I am using the struct messenger_msg of messenger component:
 
struct messenger_msg
{
  uint16_t length;
  uint8_t type;
  string body;
} __attribute__ ((packed));
 
  So, I declare and set the fields in my component:
 
   messenger_msg mymsg;
   mymsg.type = 0x0A;
   mymsg.body.append(Test);
   mymsg.length = (sizeof(messenger_msg));
 
  And the other part of the client (using socket):
 
int Mysocket, numbytes;
char buf[MAXDATASIZE];
struct hostent *he;
struct sockaddr_in seu_endereco;
 
if ((he=gethostbyname(localhost)) == NULL)   /* send host info */
{
herror(gethostbyname);
exit(1);
}
 
seu_endereco.sin_family = AF_INET;
seu_endereco.sin_port = htons(PORTA);
seu_endereco.sin_addr = *((struct in_addr *)he-h_addr);
bzero((seu_endereco.sin_zero), 8);
 
if (send(Mysocket, mymsg, mymsg.length, 0) == -1) {
perror(send);
close(Mysocket);
exit(0);
}
 
  Where PORTA==2603;
 
  But when I run it, the server client (messenger) prints:
 
  00077|messenger_core|DBG:Copy 8 bytes to message
  00078|messenger|DBG:Check message completeness 512 (expected 512)
  00079|messenger_core|DBG:Received packet of length 512
  00080|messenger|DBG:Message posted as Msg_event
  00081|messenger|DBG:Received packet of length 512
  00082|messenger_core|DBG:Copy 2 bytes to message
  00083|messenger|DBG:Check message completeness 2 (expected 62559)
  00084|messenger_core|DBG:Copy 502 bytes to message
  00085|messenger|DBG:Check message completeness 504 (expected 62559)
  00086|messenger|DBG:me.msg-length: 512 and sizeof(messenger_msg)+1: 9
  00087|messenger|DBG:Received string ��Q�
 
  The string Test is not printed. It shows ��Q� instead. What am I doing
  wrong? Is it the length of the message that I am setting doing
 mymsg.length
  = (sizeof(messenger_msg)); ? Or in the way I am using socket send
 function
  in client (send(Mysocket, mymsg, mymsg.length, 0)) ?
 
  Thanks for help.
 
  Best Regards.
 
  2011/6/18 kk yap yap...@stanford.edu
 
  Hi Ricardo,
 
  You might want to add a length and type in front of the string.  :)
 
  Regards
  KK
 
  On 18 June 2011 14:46, Ricardo Bennesby ricardo.benne...@gmail.com
  wrote:
   Hi.
  
   I am writing component in C++ that uses messenger component.
  
   I have a client function that send a string to the own component. As
   follows:
  
 void comp::sendMessageOtherAs(){
   ClientSocket theSocket (localhost, 2603 );
   string request;
   request = Test;
   theSocket  request  \n;
   lg.dbg(Echo sent);
 }
  
   The server part is did by messenger component, calling the
   handle_message
   function;
  
   But the result, when the handle_message is invoked is:
  
   00108|messenger_core|DBG:Starting connection with idleInterval 0
   00109|messenger_core|DBG:Received packet of length 0
   00110|messenger|DBG:Message posted as Msg_event
   00111|messenger_core|DBG:TCP socket connection accepted
   00112|messenger_core|DBG:Copy 2 bytes to message
   00113|messenger|DBG:Check message completeness 2 (expected 21349)
   00114|messenger_core|DBG:Copy 31 bytes to message
   00115|messenger|DBG:Check message completeness 33 (expected 21349)
   00116|messenger_core|DBG:Received packet of length 3
   00117|messenger_core|DBG:Received disconnection request
   00118|messenger|DBG:Message posted as Msg_event
   00119|messenger_core|DBG:socket closed
  
   And the handler messenger has the code:
  
   switch (me.msg-type)
   {
   case MSG_DISCONNECT:
 return STOP;
 break;
   case MSG_ECHO:
 VLOG_DBG(lg, Got echo request);
 reply_echo(me);
 return STOP;
 break;
   case MSG_ECHO_RESPONSE:
 VLOG_DBG(lg, Echo reply received);
 return STOP;
 break;
   case MSG_NOX_STR_CMD:
 char mstring[ntohs(me.msg-length)-sizeof(messenger_msg)+1];
 memcpy(mstring, me.msg-body,
   

[nox-dev] Error in send a string using messenger component

2011-06-18 Thread Ricardo Bennesby
Hi.

I am writing component in C++ that uses messenger component.

I have a client function that send a string to the own component. As
follows:

 * void comp::sendMessageOtherAs(){
ClientSocket theSocket (localhost, 2603 );
string request;
request = Test;
theSocket  request  \n;
lg.dbg(Echo sent);
  }*

The server part is did by messenger component, calling the handle_message
function;

But the result, when the handle_message is invoked is:

*00108|messenger_core|DBG:Starting connection with idleInterval 0
00109|messenger_core|DBG:Received packet of length 0
00110|messenger|DBG:Message posted as Msg_event
00111|messenger_core|DBG:TCP socket connection accepted
00112|messenger_core|DBG:Copy 2 bytes to message
00113|messenger|DBG:Check message completeness 2 (expected 21349)
00114|messenger_core|DBG:Copy 31 bytes to message
00115|messenger|DBG:Check message completeness 33 (expected 21349)
00116|messenger_core|DBG:Received packet of length 3
00117|messenger_core|DBG:Received disconnection request
00118|messenger|DBG:Message posted as Msg_event
00119|messenger_core|DBG:socket closed
*
And the handler messenger has the code:

*switch (me.msg-type)
{
case MSG_DISCONNECT:
  return STOP;
  break;
case MSG_ECHO:
  VLOG_DBG(lg, Got echo request);
  reply_echo(me);
  return STOP;
  break;
case MSG_ECHO_RESPONSE:
  VLOG_DBG(lg, Echo reply received);
  return STOP;
  break;
case MSG_NOX_STR_CMD:
  char mstring[ntohs(me.msg-length)-sizeof(messenger_msg)+1];
  memcpy(mstring, me.msg-body,
ntohs(me.msg-length)-sizeof(messenger_msg));
  mstring[ntohs(me.msg-length)-sizeof(messenger_msg)] = '\0';
  VLOG_DBG(lg, Received string %s, mstring);
  break;
}*

Shouldn't the message be of MSG_NOX_STR_CMD type and prints the string sent?
Or the way I am sending the string is wrong?

Sorry if I did'n made me clear.
Thanks for help.
Regards.

-- 
Ricardo Bennesby da Silva
Ciência da Computação - UFAM
LabCIA - Laboratório de Computação Inteligente e Autônoma
___
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev


Re: [nox-dev] Error in send a string using messenger component

2011-06-18 Thread kk yap
Hi Ricardo,

You might want to add a length and type in front of the string.  :)

Regards
KK

On 18 June 2011 14:46, Ricardo Bennesby ricardo.benne...@gmail.com wrote:
 Hi.

 I am writing component in C++ that uses messenger component.

 I have a client function that send a string to the own component. As
 follows:

   void comp::sendMessageOtherAs(){
     ClientSocket theSocket (localhost, 2603 );
     string request;
     request = Test;
     theSocket  request  \n;
     lg.dbg(Echo sent);
   }

 The server part is did by messenger component, calling the handle_message
 function;

 But the result, when the handle_message is invoked is:

 00108|messenger_core|DBG:Starting connection with idleInterval 0
 00109|messenger_core|DBG:Received packet of length 0
 00110|messenger|DBG:Message posted as Msg_event
 00111|messenger_core|DBG:TCP socket connection accepted
 00112|messenger_core|DBG:Copy 2 bytes to message
 00113|messenger|DBG:Check message completeness 2 (expected 21349)
 00114|messenger_core|DBG:Copy 31 bytes to message
 00115|messenger|DBG:Check message completeness 33 (expected 21349)
 00116|messenger_core|DBG:Received packet of length 3
 00117|messenger_core|DBG:Received disconnection request
 00118|messenger|DBG:Message posted as Msg_event
 00119|messenger_core|DBG:socket closed

 And the handler messenger has the code:

 switch (me.msg-type)
     {
     case MSG_DISCONNECT:
   return STOP;
   break;
     case MSG_ECHO:
   VLOG_DBG(lg, Got echo request);
   reply_echo(me);
   return STOP;
   break;
     case MSG_ECHO_RESPONSE:
   VLOG_DBG(lg, Echo reply received);
   return STOP;
   break;
     case MSG_NOX_STR_CMD:
   char mstring[ntohs(me.msg-length)-sizeof(messenger_msg)+1];
   memcpy(mstring, me.msg-body,
 ntohs(me.msg-length)-sizeof(messenger_msg));
   mstring[ntohs(me.msg-length)-sizeof(messenger_msg)] = '\0';
   VLOG_DBG(lg, Received string %s, mstring);
   break;
     }

 Shouldn't the message be of MSG_NOX_STR_CMD type and prints the string sent?
 Or the way I am sending the string is wrong?

 Sorry if I did'n made me clear.
 Thanks for help.
 Regards.

 --
 Ricardo Bennesby da Silva
 Ciência da Computação - UFAM
 LabCIA - Laboratório de Computação Inteligente e Autônoma


 ___
 nox-dev mailing list
 nox-dev@noxrepo.org
 http://noxrepo.org/mailman/listinfo/nox-dev


___
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev