Oppure

Loading
06/07/10 18:42
ShellC91
Ciao a tutti come posso fare usando i socket (Windows) per verificare quando una connessione cade?

Cosa ritornano la send() e la recv() quando una connessione cade? ritornano 0 o -1 ?

Quale tipo di controllo devo mettere?

Ringrazio in anticipo tutti.
aaa
06/07/10 19:09
send
msdn.microsoft.com/en-us/library/…(VS.85).aspx

"Return Value - If no error occurs, send returns the total number of bytes sent, which can be less than the number requested to be sent in the len parameter. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError."


recv
msdn.microsoft.com/en-us/library/…(v=VS.85).aspx
"Return Value - If no error occurs, recv returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data received. If the connection has been gracefully closed, the return value is zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError."
06/07/10 19:12
ShellC91
quindi da quello che ho capito sarebbe:

if(send(...) == SOCKET_ERROR)
{
      ...
}


e

if(recv(...) == 0)
{
      ...
}


E' giusto?
aaa
06/07/10 19:14
Devi sempre controllare (con send e recv) il SOCKET_ERROR e, in questo caso, controllare l'errore specifico con la API WSAGetLastError.

Per la recv, se hai uno zero (come scritto) la connessione è stata chiusa "correttamente".
Ultima modifica effettuata da 06/07/10 19:17