C++ tutorial pdf 2015

Windows” because the code snippets shown over here will c++ tutorial pdf 2015 only on Windows. The windows api to socket programming is called winsock. Sockets are the fundamental “things” behind any kind of network communications done by your computer. For example when you type www.

Same with any chat client like gtalk or skype. Any network communication goes through a socket. This tutorial assumes that you have basic knowledge of C and pointers. The WSAStartup function is used to start or initialise winsock library. WSADATA structure which will hold additional information after winsock has been loaded. OK , so next step is to create a socket. Ok , so you have created a socket successfully.

We can connect to www. Apart from SOCK_STREAM type of sockets there is another type called SOCK_DGRAM which indicates the UDP protocol. This type of socket is non-connection socket. In this tutorial we shall stick to SOCK_STREAM or TCP sockets.

So we need 2 things , IP address and port number to connect to. First is create a sockaddr_in structure with proper values filled in. The sockaddr_in has a member called sin_addr of type in_addr which has a s_addr which is nothing but a long. It contains the IP address in long format. IP address to a long format.

Here we used the ip address of google. A little later on we shall see how to find out the ip address of a given domain name. It needs a socket and a sockaddr structure to connect to. Here is a code sample.

scroll to top