linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Lejanson C. Go" <lejanson@ntsp.nec.co.jp>
To: linux-c-programming@vger.kernel.org
Subject: another socket connection question
Date: Thu, 03 Jul 2003 11:14:58 +0800	[thread overview]
Message-ID: <3F039FB2.3070600@hq.ntsp.nec.co.jp> (raw)


             Client                       Server
               .                             .
               .                             .
               .    retry connect until      .
               o---------------------------->.
               .         success             .
               .                             .
               .<----------------------------o
               .                             .
               .                             .
               .                             .
               .                             .
               .      getServerNodeId        .
               o---------------------------->.  Server wont be ready
               .    retry until success      .  until some time
               .                             .
               .                             .



I am trying to make a client server application where a client
is trying to get the nodeId of the server.

The server opens up its ports and my client connects to the server.
If unsuccessful the client side will retry to connect until it is
successful.

Considering the client is connected. Client application then will
send a GetServerNodeId request to the server.

What if the server is not ready to receive any request, how will
I make my GetServerNodeId request to be sent without errors? My
client application displays "Broken Pipe" when I run the client.


Steps in Testing:

1. run server
2. client connects to server until success
3. server is not ready to read requests
4. getServerNodeId - retry until success.


My problem revolves on my getServerNodeId request. Since my client
application have no way of knowing if the server is already accepting
requests from the client.

Can anyone help me please?


Here is a code snippet of the getServerNodeId :


//--------------------- SNIP -----------------------------//

inti sendNMCommand( void *data, inti size )
{
   int ret = -1;

   if (nmCmdSockConnected == FALSE)
   {
     return (ERR);
   }

   ret = write( nmCmdSock, data, size );

   if (ret != size)
   {
       return (ERR);
   }

   return( ret );
}


inti getServerNodeId(void)
{
   MSG_HEADER     header;
   NODE_INFO      node_info;
   int    stat;
   char   *str;
   struct in_addr tmpAddr;

   memset( &header, 0, sizeof(header));
   memset( &node_info, 0, sizeof(node_info));

   header.msg_type     = CLI_NM_MSG_TYPE_NODE_ID | 
CLI_NM_MSG_TYPE_COMMAND_SHOW;
   header.msg_size = sizeof(header);

   stat = sendNMCommand( &header, sizeof(header) );

   if (stat == ERR )
   {
     return(ERR);
   }

   memset( &header, 0, sizeof(header));

   stat = read(nmCmdSock, &header, sizeof(header));

   if (stat <= 0)
   {
     return (ERR);
   }

   if (header.msg_ret_code != CLI_NM_MSG_RETCODE_SUCCESS)
   {
     return (ERR);
   }

   if (header.msg_type == (CLI_NM_MSG_TYPE_NODE_ID | 
CLI_NM_MSG_TYPE_COMMAND_SHOW))
   {
     stat = recvNMData( &node_info, sizeof(node_info), &nmCmdSock);
     if (stat == ERR)
     {
       return (ERR);
     }

     tmpAddr.s_addr = node_info.node_id;
     str = inet_ntoa(tmpAddr);
     setPrompt(str);
   }
   else
   {
     return (ERR);
   }
   return(OK);
}


//--------------------- SNIP -----------------------------//





->end.










             reply	other threads:[~2003-07-03  3:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-03  3:14 Lejanson C. Go [this message]
2003-07-03  3:45 ` another socket connection question ronkhu
2003-07-03  6:12 ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F039FB2.3070600@hq.ntsp.nec.co.jp \
    --to=lejanson@ntsp.nec.co.jp \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).