linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* another socket connection question
@ 2003-07-03  3:14 Lejanson C. Go
  2003-07-03  3:45 ` ronkhu
  2003-07-03  6:12 ` Glynn Clements
  0 siblings, 2 replies; 3+ messages in thread
From: Lejanson C. Go @ 2003-07-03  3:14 UTC (permalink / raw)
  To: linux-c-programming


             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.










^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: another socket connection question
  2003-07-03  3:14 another socket connection question Lejanson C. Go
@ 2003-07-03  3:45 ` ronkhu
  2003-07-03  6:12 ` Glynn Clements
  1 sibling, 0 replies; 3+ messages in thread
From: ronkhu @ 2003-07-03  3:45 UTC (permalink / raw)
  To: linux-c-programming

( after successful connection)how about  making the client wait
for a certain u-can-now-send-me-requests message
from the server before proceeding in sending requests?

Lejanson C. Go wrote:

>
>             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.
>
>
>
>
>
>
>
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: another socket connection question
  2003-07-03  3:14 another socket connection question Lejanson C. Go
  2003-07-03  3:45 ` ronkhu
@ 2003-07-03  6:12 ` Glynn Clements
  1 sibling, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2003-07-03  6:12 UTC (permalink / raw)
  To: Lejanson C. Go; +Cc: linux-c-programming


Lejanson C. Go wrote:

> 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.

"Broken Pipe" means that you are writing to a closed descriptor.

Is this using TCP or UDP?

For TCP, connect() will either fail or will block until the server has
acknowledged the connection. Once the connection has been established,
you just send the request once and wait for the reply.

If you're using UDP, you should probably learn how TCP is implemented,
because you will end up re-implementing many of the mechanisms which
TCP uses (sequencing, acknowledgements, flow control, etc).

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-03  6:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-03  3:14 another socket connection question Lejanson C. Go
2003-07-03  3:45 ` ronkhu
2003-07-03  6:12 ` Glynn Clements

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).