Need help, my message takes 14 seconds to reach the server.

My RCM4010 working as a client to send message to a simple server written with Delphi. The server displays what is sent to it.

My network is a simple one with only one router. RCM4010 and my PC are hooked up to this router.

After message is sent, it takes about 14 sec to reach the server and be displaed there. I display the status of my RCM4010 in the stdio. It is found that the messages are sent right away and the socket closed properly after sending all the messages. My server can then display the message 14 seconds later.

I run another client (written by Delphi as well) in another PC. Its message is displayed immediately on the server.

I pinged my RCM4010 and the RTT is 2 mS.

My code is listed below. Can someome let me know what mistake I made?

#define TCPCONFIG 1

#use “dcrtcp.lib”

/*

  • Remote computer to contact:
    */
    #define DEST “www.rabbit.com
    #define PORT 50

////////////////////////////////////////////////////////////////////////

void main()
{
char buffer[100]; /* Currently (DC 7.30), printf() has max 127 bytes it can output. */
int bytes_read, aa, ab, i;
longword destIP;
tcp_Socket socket;
unsigned long int T1;

destIP = 3232235878; //192.168.1.102
// Start network and wait for interface to come up (or error exit).
sock_init_or_exit(1);

tcp_open(&socket,0,destIP,PORT,NULL);

printf("Waiting for connection...

");
while(!sock_established(&socket) && sock_bytesready(&socket)==-1) {
tcp_tick(NULL);
}

printf("Connection established, sending a message...

");

for (i=0; i<=99; ++i)	{
  aa = sock_write(&socket,"Frank ",6);
      printf("Sock awrite = %d; i=%d 

", aa, i);
}

sock_close(&socket);
printf("waiting for socket to close!
");

ab = 0;
do{
aa = tcp_tick(NULL);
ab=1;
if(ab=0) printf("Still waiting!!
");
}
while(aa==0);

printf("
Connection closed…
");

}

:o :confused:

I think you’re misusing tcp_tick(). tcp_v1.pdf calls out the return values for that function:

RETURN VALUE
0: Connection reset or closed by other host or NULL was passed in.
!0: Connection is fine.

On a guess I’d say you were falling right through your while(aa==0), getting the closing printf, and moving on without any more tcp_ticks. Your far end then resets the connection in 10-15 seconds.

Try this instead:
sock_close (&socket) ;
start = MS_TIMER ;
while (sock_alive(&socket))
{
[indent] tcp_tick (NULL) ;
if (labs(MS_TIMER - start) > 10000L)
[indent]break ;
[/indent] }
[/indent]

Good luck!

Hello Islarry:

Thanks for the help.

It is really found out that the far end closes in about 14 sec then it displays the received message. However I could get it close promptly. The sock_alive(&socket) inside the while loop seems to have nothing to do to speed up the close of the far end.

Thanks and regards

Frank
:confused: