How to check a socket is disconnected
-
I use raw Windows sockets. How to check whether the other side of the connection is closed? Thanks
hi, i really need help in windows sockets, here is a function i wrote to connect to server: //----------- Function Implementation -------------------------------- bool ConnectToSocket() { if (WSAVERNOTSUPPORTED == WSAStartup(MAKEWORD(2,0),&WSAData)) { printf("WSAStartup Failed!\r\n"); return FALSE; }//end if else { printf("WSAStartup Success\r\n"); }//end else // construct socket sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if (sock == INVALID_SOCKET) { printf("Failed to construct socket!\r\n"); WSACleanup(); return FALSE; }//end if else { printf("Socket construction....Success\r\n"); }//end else // fill in socket address struct and connect to server sa.sin_family = AF_INET; sa.sin_port = 23; sa.sin_addr.S_un.S_addr = inet_addr("147.234.12.233"); int iErr = connect( sock,(SOCKADDR *)&sa,sizeof(sa)); return TRUE; } it doesn't seem to work ,i dont know why..... also how do i receive and send data???? please help me i am desperate! tnx a lot yaron
-
hi, i really need help in windows sockets, here is a function i wrote to connect to server: //----------- Function Implementation -------------------------------- bool ConnectToSocket() { if (WSAVERNOTSUPPORTED == WSAStartup(MAKEWORD(2,0),&WSAData)) { printf("WSAStartup Failed!\r\n"); return FALSE; }//end if else { printf("WSAStartup Success\r\n"); }//end else // construct socket sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if (sock == INVALID_SOCKET) { printf("Failed to construct socket!\r\n"); WSACleanup(); return FALSE; }//end if else { printf("Socket construction....Success\r\n"); }//end else // fill in socket address struct and connect to server sa.sin_family = AF_INET; sa.sin_port = 23; sa.sin_addr.S_un.S_addr = inet_addr("147.234.12.233"); int iErr = connect( sock,(SOCKADDR *)&sa,sizeof(sa)); return TRUE; } it doesn't seem to work ,i dont know why..... also how do i receive and send data???? please help me i am desperate! tnx a lot yaron
there are some possebilities the first 1 is that the server is not up you don't check errors at all in the winsock.h there are list of errors you can take the error value (which is unsigned int)and send it to acheckerror function which does switch case over all the possebilities and then know more specific what is the problem any way good luck Rami Buchnik