What I want to understand is how it all works, including the following parts:

WSADATA wsaData;
SOCKET ConnectSocket = INVALID_SOCKET;
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);

WSADATA is info, but what info is it specifically?
WSAStartup is a function to initiate WS2_32.dll. What is the differenece between initiating WS2_32.dll and SOCKET?

Hi Wajed

To answer your questions:

"WSADATA is info, but what info is it specifically?"

For Windows API methods your first port of call will often be MSDN. Heres the MSDN on WSAStartup which explains the WSADATA struct.
MSDN: WSAStartup function

"What is the differenece between initiating WS2_32.dll and SOCKET?"

In windows to gain access to sockets support first you must initialise the sockets layer : winsock2 in your case. This done by loading the functions from the winsock dll.

Note: If you ever move to *nix based systems socket support does not require initilisation in this manner. Just include the relavent headers.

Then when you initialise a socket itself your setting up an actual socket to begin communications.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.