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(&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(&socket,"client actif
",30);
do {
bytes_read=sock_fastread(&socket,buffer,sizeof(buffer)-1);
if(bytes_read>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(&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.