OVH Cloud OVH Cloud

sockets devenant bloquantes dans un service

1 réponse
Avatar
Stéphane GRAZIANO
Bonjour à tous j'ai un petit problème,

J'ai écrit une fonction qui me permet de me connecter sur une ip avec un
port donné en TCP/IP. Elle met le socket non bloquant, jusque là tout va
bien...(si je me connecte sur une adresse qui n'existe pas (mais dans le
réseau) la fonction échoue directement)

Quand je met cette même fonction dans un service NT, si je me connecte sur
une adresse qui n'existe pas (mais dans le réseau) la fonction échoue au
bout de 20 secondes (ça fait long quand même...).

Je ne comprend pas pourquoi il y a un fonctionnement différent du service à
l'application "normale".

Voilà le code :

BOOL MaClasse::OpenNetwork(char * HOSTNAME,DWORD PORTNUM)
{

//WSAStartup est déjà ok

this->ServerSock =socket(AF_INET,SOCK_STREAM,IPPROTO_TCP));

ULONG Param = 1;
ioctlsocket( this->ServerSock, FIONBIO, &Param );//non blocking


inet_addr(HOSTNAME)

SOCKADDR_IN sockAddr;
memset(&sockAddr,0,sizeof(sockAddr));

LPSTR lpszAscii = NULL;
sockAddr.sin_family = AF_INET;

if (lpszAscii == NULL)
sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);


this->destination_sin.sin_family = AF_INET;

// Retrieve the host information corresponding to the host name.
this->phostent = gethostbyname (HOSTNAME));

// Assign the socket IP address.
memcpy ((char FAR *)&(this->destination_sin.sin_addr),
this->phostent->h_addr,
this->phostent->h_length);

// Convert to network ordering.
this->destination_sin.sin_port = htons ((USHORT)PORTNUM);


// Establish a connection to the server socket.
connect (this->ServerSock,
(PSOCKADDR) &this->destination_sin,
sizeof (this->destination_sin));

return TRUE;

}


En vous remerciant d'avance pour votre aide,
Stef++

1 réponse

Avatar
Stéphane GRAZIANO
Ouppps il s'agissait d'une erreur de manip (oubli de supprimer le service
dans la base de registres)

Ca marche super bien :o)
Désolé de vous avoir dérangé

Stef++