I just made a server and client programs (finally!!) but there's a problem with my client program. The problem is , when the server isn't up , the client abnormally terminates and displays a windows error (the one with "send report" ..etc). How do i check if the server is up , and if not , try another address for example?
here's my client's simple code :
ver = MAKEWORD(1,1);
hostEntry = gethostbyname("localhost");
printf("Error getting host : %s\n", WSAGetLastError());
printf("Host gathered ..\n");
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(theSocket == INVALID_SOCKET)
printf("Error socket : %s\n", WSAGetLastError());
printf("Socket created ..\n");
serverInfo.sin_family = AF_INET;
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(666);
sizeof(sockaddr)) == -1)
printf("Error connectiog : %s", WSAGetLastError());
printf("connected ... \n\n\n");
fgets(buffer, sizeof(buffer), stdin);
if( send(theSocket, buffer, strlen(buffer), 0) == SOCKET_ERROR)
printf("Error getting host : %s", WSAGetLastError());
Edit : i forgot to mention that the program reaches "connect()" before it termiates , and it won't display an error even though i used error checking.
help is much appreciated..