# Problem with TCP IP connection on RCM3365

**URL:** <https://forums.digi.com/t/problem-with-tcp-ip-connection-on-rcm3365/9911>\
**Category:** Rabbit\
**Created:** [June 15, 2007, 7:59pm UTC](https://forums.digi.com/t/problem-with-tcp-ip-connection-on-rcm3365/9911 "2007-06-15T19:59:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![coldMon](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@coldMon](https://forums.digi.com/u/coldMon)\
**Post date:** [June 15, 2007, 7:59pm UTC](https://forums.digi.com/t/problem-with-tcp-ip-connection-on-rcm3365/9911/1 "2007-06-15T19:59:36Z")

</div>

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(&amp;socket,0,destIP,PORT,NULL);
tcp_extopen(&amp;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(&amp;socket,buffer,sizeof(buffer)-1);

	if(bytes_read&gt;0) {
		buffer[bytes_read] = '\0';
		printf("%s",buffer);
	}
} while(tcp_tick(&amp;socket));

sock_close(&amp;socket);

```

}

---

<div class="post-metadata">

**Author:** ![coldMon](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@coldMon](https://forums.digi.com/u/coldMon)\
**Post date:** [June 21, 2007, 7:45pm UTC](https://forums.digi.com/t/problem-with-tcp-ip-connection-on-rcm3365/9911/2 "2007-06-21T19:45:13Z")

</div>

define the tcp socket variable globally…

call sock\_init(); ONLY once in side the main program,

in the sendData() method re initiate the socket if its not “alive” this can be checked using sock\_alive(&socket),

my problem is solved…
