problem with Connection closed socket (re-loop)

Hello,

To communicate with my server i have tried active.c who works but my problem is this part :

" while(tcp_tick(&socket));

sock_abort(&socket);
printf("

Connection closed…
“);”

doesn’t work.

I must implement a interrupt function but as my connection doesn’t close, i can’t re-loop my interrupt, excepted that it works. So if you have any ideas to help me i will appreciate this.

If the remote end closes its end of the socket, then the Rabbit should eventually close the socket and exit that while loop.

You can call sock_close() if you want to initiate closure of the socket.

After that call to sock_abort(), you should be able to go right back to calling tcp_open() on the socket structure to open another connection.

void main(){

auto int key, channel;
  // Initialize the controller
brdInit();

// Configure all inputs to be general digital inputs
for(channel = 0; channel < BL_DIGITAL_IN; ++channel)
{
setDigIn(channel);
}

if (digIn(3) != 0)
{
   char buffer[2048];
 int bytes_read;
  	longword  destIP;
	tcp_Socket socket;
   int digIn();

//création de la socket
sock_init_or_exit(1);

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);

printf("Waiting for connection...

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

printf("Connection established, sending request...

");

/*
 *  When tcp_tick()-ing on a specific socket, we get non-zero return while
 *  it is active, and zero when it is closed (as used here).
 */

sock_write(&amp;socket,"client actif 

",30);

do {
	bytes_read=sock_fastread(&amp;socket,buffer,sizeof(buffer)-1);

	if(bytes_read&gt;0) {
		buffer[bytes_read] = '\0';
		/*
		 * By using the "%s" format, if there are "%" in the buffer, printf()
		 *  won't try to interpret them!
		 */
		printf("%s",buffer);
	}
}

while(tcp_tick(&socket));

sock_abort(&amp;socket);
printf("

Connection closed…
");
}
}

As you see (in this part) it’s a the end, i have tried sock_close() without succes. I don’t understand why my function stay in the do and doesn’t continue.

Do you understand that the “while” is part of the “do” above it? “do { … } while (condition);” is a loop that executes the statements at least once, and continues to loop as long as the condition is true. In this case, you’ll leave the “do” when tcp_tick() returns false (0), which it should do if the remote end has closed the socket correctly.

Thank for this answer TomCollins, so I need to correctly close my server.