VC++ console application - client / Server
-
It's confusing! Let’s imagine my public IP address is 86.57.91.237. Now I want to use that IP in the code below: ... WSAData ws; struct sockaddr_in sock; int resSock, bnd; WSAStartup(MAKEWORD(2, 2), &ws); resSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (resSock != INVALID_SOCKET){ sock.sin_family = AF_INET; sock.sin_port = htons(3377); sock.sin_addr.S_un.S_addr = inet_addr("86.57.91.237"); } bnd=bind(resSock, (struct sockaddr *)&sock, sizeof(sock)); if (bnd != SOCKET_ERROR) cout << "Bind Successful" << endl; else cout << GetLastError() << endl; ... why does this program show error code 10049? Error code 10049 means: “The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer”. I want to see “Bind Successful” message.
Run "ipconfig /all" at the command prompt. Look at the results, there should be data given about each NIC card on YOUR machine. Look at the line that says "IP Address.......xxx.xxx.xxx.xxx" (there may be several). Make a list of these IP addresses. If "86.57.91.237" is not in that list, then you can not bind to it. Meaning it is not an IP address associated with a NIC on your computer.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst