I am using following program on my rabbit device(RCM3365) in order to get some data from a web server,
This program is a little extension of the sample program (ACTIVE.C) that is available with Dynamic C .
In the web server I have a php script which returns a time variable when invoked,
The problem I am facing is when I try to call the getData() function in 5 sec intervals
I can get data for three requests but after that,
I�m getting an runtime error saying that there are no more sockets available.
Then I have tried defining the socket variable globally,
In that case I can go up to around 24 tries after that I am getting a runtime error saying �Xmem allocation failed (Out of memory)�.
what am i doing wrong?
void getData()
{
char buffer[100];
int bytes_read;
sock_buf_len = 4096;
sock_buf = xalloc(sock_buf_len);
printf( "initializing..
" );
sock_init();
// Wait for the interface to come up
while (ifpending(IF_DEFAULT) == IF_COMING_UP) {
tcp_tick(NULL);
}
if( 0L == (destIP = resolve(DEST)) ) {
printf( "ERROR: Cannot resolve \"%s\" into an IP address
", DEST );
exit(2);
}
//tcp_open(&socket,0,destIP,PORT,NULL);
tcp_extopen(&socket, IF_ANY, 0, destIP, 80, NULL, sock_buf, sock_buf_len);
printf("Waiting for connection...
");
while(!sock_established(&socket) && sock_bytesready(&socket)==-1) {
tcp_tick(NULL);
}
sock_write(&socket,"GET /time.php
",30);
do {
bytes_read=sock_fastread(&socket,buffer,sizeof(buffer)-1);
if(bytes_read>0) {
buffer[bytes_read] = '\0';
printf("%s",buffer);
}
} while(tcp_tick(&socket));
sock_close(&socket);
}