EmbeddedRelated.com
Forums

NIST time server - TCPIP problem

Started by "rhu...@gmail.com [rabbit-semi]" June 26, 2014









On 6/26/2014 2:27 PM, r...@gmail.com [rabbit-semi] wrote:
> I am trying to implement a web button that will fetch the current time from a NIST time server, with the routine based on the NIST_TIME.C sample code. My code will get the NIST time if that function is called before starting the http handler. And the http handler will work fine until an attempt is made to get the NIST time. With the attached C and HTML code, each time the user clicks the --Test-- button, a line prints in the STDIO window. But clicking the --Get NIST Time-- button kills the browser code. In the C code, a call to the function which gets the NIST time is commented out (about 10 lines from the bottom). If that line is made active, the program will get the NIST time and print it, but then the browser code doesn’t work. Obviously I know nothing when it comes to TCPIP stuff. Please, can anyone help?

Look at the #defines in the docs for the # of socket buffers and max
sockets. You probably have 1 too few.

--
------
Scott G. Henion, Consultant
Web site: http://SHDesigns.org
------


Posted by: Scott Henion



Hi Scott,

Thank you for the prompt reply. I checked the Dynamic C TCP/IP manual,
which says the MAX_SOCKETS define has been deprecated. I did not have a
value defined for MAX_TCP_SOCKET_BUFFERS, so was hoping you had nailed
the problem. Since the default value is 4, I added the line:
#define MAX_TCP_SOCKET_BUFFERS 8
and when that did not work, made it 16. That did not work either.

The code which is failing is:

printf("\nConnecting with NIST server ...\n");
sock_init();
while (ifpending(IF_DEFAULT) == IF_COMING_UP)
{
tcp_tick(NULL);
}
ip=resolve(NIST_SERVER_IP);
tcp_open(&s, 0, ip, NIST_PORT, NULL);
sock_wait_established(&s, NIST_TIMEOUT, NULL, &status);
sock_mode(&s, TCP_MODE_ASCII);
// Receive and process data -- the server will close the connection,
// which will cause execution to continue at sock_err below.
while (tcp_tick(&s))
{
sock_wait_input(&s, NIST_TIMEOUT, NULL, &status);
sock_gets(&s, buffer, 48);
}

sock_err:
if (status == -1)
{
printf("\nConnection timed out, exiting.\n");
exit(1);
}

I get the "Connection timed out, exiting" message almost instantly,
which means the sock_wait_input function is returning a status of -1,
which according to the DC manual "indicates a reset or abort." This same
code works if I haven't opened the http handler first.

Scott, I know absolutely nothing about TCP/IP stuff, and am really
struggling here. I am embarrassed to admit that I have already spent a
couple of days on this issue. Do you have any other ideas?

Thanks so much,

Roger
On 6/26/2014 2:07 PM, Scott Henion s...@shdesigns.org [rabbit-semi]
wrote:
>
> Look at the #defines in the docs for the # of socket buffers and max
> sockets. You probably have 1 too few.
>
> ------
> Scott G. Henion, Consultant
> Web site: http://SHDesigns.org
> ------
>

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
On 6/26/2014 7:48 PM, Roger Hunt r...@gmail.com [rabbit-semi] wrote:
> Hi Scott,
>
> Thank you for the prompt reply. I checked the Dynamic C TCP/IP
> manual, which says the MAX_SOCKETS define has been deprecated. I did
> not have a value defined for MAX_TCP_SOCKET_BUFFERS, so was hoping you
> had nailed the problem. Since the default value is 4, I added the line:
> #define MAX_TCP_SOCKET_BUFFERS 8
> and when that did not work, made it 16. That did not work either.
>
> The code which is failing is:
>
> printf("\nConnecting with NIST server ...\n");
> sock_init();
> while (ifpending(IF_DEFAULT) == IF_COMING_UP)
> {
> tcp_tick(NULL);
> }
> ip=resolve(NIST_SERVER_IP);
> tcp_open(&s, 0, ip, NIST_PORT, NULL);
> sock_wait_established(&s, NIST_TIMEOUT, NULL, &status);
> sock_mode(&s, TCP_MODE_ASCII);
> // Receive and process data -- the server will close the connection,
> // which will cause execution to continue at sock_err below.
> while (tcp_tick(&s))
> {
> sock_wait_input(&s, NIST_TIMEOUT, NULL, &status);
> sock_gets(&s, buffer, 48);
> }
>
> sock_err:
> if (status == -1)
> {
> printf("\nConnection timed out, exiting.\n");
> exit(1);
> }
>
> I get the "Connection timed out, exiting" message almost instantly,
> which means the sock_wait_input function is returning a status of -1,
> which according to the DC manual "indicates a reset or abort." This
> same code works if I haven't opened the http handler first.
>
> Scott, I know absolutely nothing about TCP/IP stuff, and am really
> struggling here. I am embarrassed to admit that I have already spent
> a couple of days on this issue. Do you have any other ideas?
>
> Thanks so much,

Make sure you define MAX_TCP_SOCKET_BUFFERS before you #use any libraries.

The while loop with sock_wait_input() will kill the http server while it
waits for data. Any time you have something waiting, you need to poll
for data and if none ready call tcp_tick(NULL) and http_handler();

It will work as is, but the http server wil be unresponsive while it
waits. The same applies to sock_wait_established().

--
------
Scott G. Henion, Consultant
Web site: http://SHDesigns.org
------


Posted by: Scott Henion