I am trying to do a simple socket connect and test whether my connection succeeds or not. My reading tells me that connect upon failure should return the value of -1. I disabled the device and I am attempting to connect to, and yet my program still says the connection was successful. So I know I've goofed at this point. Does anyone see anything wrong with my testing or have just got my socket setup wrong..... Thanks for any help-
Code://we will need variables to hold the client socket. //thus we declare them here. cout <<"opening client socket"<<endl; SOCKET client; client=socket(AF_INET,SOCK_DGRAM,0); sockaddr_in from; // memset((char *) &from,0,sizeof(from)); from.sin_family=AF_INET; from.sin_addr.s_addr=inet_addr ("172.20.30.30"); from.sin_port=htons((u_short)6101); int fromlen=sizeof(from); //connect to printer if ((connect (client, (struct sockaddr*)&from, sizeof from)==-1)) { cout <<"client connect failed"<<endl; } else if ((connect (client, (struct sockaddr*)&from, sizeof from)!=-1)) { cout <<"client connection successful"<<endl; }



LinkBack URL
About LinkBacks


