| Newsgroups |
gmane.comp.hardware.rabbit-semiconductor |
| Message-ID |
<[email protected]> |
On 6/26/2014 7:48 PM, Roger Hunt [email protected] [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
------------------------------------------