Winsock 2.2 Download

Posted on by

WINSOCK 2 WINDOWS SOCKET PROGRAM EXAMPLES PART 1. What do we have in this chapter Windows Sockets 2 vs Linux Sockets Client and Server Communication. Winsock tutorial Socket programming in C on windows. Socket programming with winsock. This is a quick guidetutorial to learning socket programming in C language on Windows. Windows because the code snippets shown over here will work 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. Before you begin. This tutorial assumes that you have basic knowledge of C and pointers. Also download Visual C 2. Express Edition. Initialising Winsock. Winsock first needs to be initialiased like this. Initialise Winsock. Winsock Library. int mainint argc, char rgv. Initialising Winsock. Windows-Repair-2.png' alt='Winsock 2.2 Download' title='Winsock 2.2 Download' />Tweaking. Windows Repair is an allinone repair tool to help fix a large majority of known Windows problems including registry errors and file permissions. Spybot Search Destroy 2. Beta 6 is an application designed for the removal of spyware, malware and other intrusive software. RefreshPC, Bad Shortcut Killer, XP TCPIP Repair and other freeware utilities from WareSoft Software. Hi Everyone Before finally getting all of my DSL problems resolved, a technician from Microsoft requested a run the following command after going to Start. Artcam Clipart more. WSAStartupMAKEWORD2,2, wsa 0. Failed. Error Code d,WSAGet. Last. Error. printfInitialised. The WSAStartup function is used to start or initialise winsock library. It takes 2 parameters the first one is the version we want to load and second one is a WSADATA structure which will hold additional information after winsock has been loaded. If any error occurs then the WSAStartup function would return a non zero value and WSAGet. Last. Error can be used to get more information about what error happened. OK, so next step is to create a socket. Creating a socket. The socket function is used to create a socket. Here is a code sample Create a TCP socket. Winsock Library. int mainint argc, char rgv. Initialising Winsock. WSAStartupMAKEWORD2,2, wsa 0. Failed. Error Code d,WSAGet. Last. Error. printfInitialised. AFINET, SOCKSTREAM, 0 INVALIDSOCKET. Could not create socket d, WSAGet. Last. Error. printfSocket created. Function socket creates a socket and returns a socket descriptor which can be used in other network commands. The above code will create a socket of Address Family AFINET this is IP version 4Type SOCKSTREAM this means connection oriented TCP protocolProtocol 0 or IPPROTOTCP, IPPROTOUDP It would be a good idea to read some documentation here. Ok, so you have created a socket successfully. But what next Next we shall try to connect to some server using this socket. We can connect to www. Note. Apart from SOCKSTREAM type of sockets there is another type called SOCKDGRAM which indicates the UDP protocol. This type of socket is non connection socket. In this tutorial we shall stick to SOCKSTREAM or TCP sockets. Connect to a Server. We connect to a remote server on a certain port number. So we need 2 things, IP address and port number to connect to. To connect to a remote server we need to do a couple of things. First is create a sockaddrin structure with proper values filled in. Lets create one for ourselves struct sockaddrin server. Have a look at the structures IPv. AFINET sockets. struct sockaddrin. AFINET, AFINET6. Saddr. INADDR, INADDR, FAR PINADDR. AFxxx. char sadata1. The sockaddrin has a member called sinaddr of type inaddr which has a saddr which is nothing but a long. It contains the IP address in long format. Function inetaddr is a very handy function to convert an IP address to a long format. This is how you do it server. So you need to know the IP address of the remote server you are connecting to. 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. The last thing needed is the connect function. It needs a socket and a sockaddr structure to connect to. Here is a code sample. Create a TCP socket. Winsock Library. int mainint argc, char rgv. Initialising Winsock. WSAStartupMAKEWORD2,2, wsa 0. Failed. Error Code d,WSAGet. Last. Error. printfInitialised. Create a socket. ifs socketAFINET, SOCKSTREAM, 0 INVALIDSOCKET. Could not create socket d, WSAGet. Last. Error. printfSocket created. AFINET. server. sinport htons 8. Connect to remote server. Connected. It cannot be any simpler. It creates a socket and then connects. If you run the program it should show Connected. Try connecting to a port different from port 8. OK, so we are now connected. Lets do the next thing, sending some data to the remote server. Quick Note. The concept of connections apply to SOCKSTREAMTCP type of sockets. Connection means a reliable stream of data such that there can be multiple such streams each having communication of its own. Think of this as a pipe which is not interfered by other data. Other sockets like UDP, ICMP, ARP dont have a concept of connection. These are non connection based communication. Which means you keep sending or receiving packets from anybody and everybody. Sending Data. Function send will simply send data. It needs the socket descriptor, the data to send and its size. Here is a very simple example of sending some data to google. Create a TCP socket. Winsock Library. int mainint argc, char rgv. Initialising Winsock. WSAStartupMAKEWORD2,2, wsa 0. Failed. Error Code d,WSAGet. Last. Error. printfInitialised. Create a socket. ifs socketAFINET, SOCKSTREAM, 0 INVALIDSOCKET. Could not create socket d, WSAGet. Last. Error. printfSocket created. AFINET. server. sinport htons 8. Connect to remote server. Connected. Send some data. GET HTTP1. 1rnrn. Send failed. putsData Sendn. In the above example, we first connect to an ip address and then send the string message GET HTTP1. The message is actually a http command to fetch the mainpage of a website. Now that we have send some data, its time to receive a reply from the server. So lets do it. Receiving Data. Function recv is used to receive data on a socket. In the following example we shall send the same message as the last example and receive a reply from the server. Create a TCP socket. Winsock Library. int mainint argc, char rgv. Initialising Winsock. WSAStartupMAKEWORD2,2, wsa 0. Failed. Error Code d,WSAGet. Last. Error. printfInitialised. Create a socket. ifs socketAFINET, SOCKSTREAM, 0 INVALIDSOCKET. Could not create socket d, WSAGet. Last. Error. printfSocket created. AFINET. server. sinport htons 8. Connect to remote server. Connected. Send some data. GET HTTP1. 1rnrn. Send failed. putsData Sendn. Receive a reply from the server. SOCKETERROR. putsrecv failed. Reply receivedn. Add a NULL terminating character to make it a proper string before printing. Here is the output of the above code. Initialising Winsock. Initialised. Socket created. HTTP1. 1 3. 02 Found. Location http www. Cache Control private. Content Type texthtml charsetUTF 8. Set Cookie PREFID7da. FF0 TM1. 32. 48. LM1. SPdl. Mu. 0TE. E3. QKrmd. B expiresWed, 2. Dec 2. 01. 3 0. 7 0. GMT path domain. Date Mon, 2. Dec 2. GMT. Content Length 2. X XSS Protection 1 modeblock. X Frame Options SAMEORIGIN. HTML lt HEAD lt meta http equivcontent type contenttexthtml charsetutf 8. TITLE 3. 02 Movedlt TITLE lt HEAD lt BODY. H1 3. 02 Movedlt H1. The document has moved. A HREFhttp www. A. BODY lt HTML. Press any key to continue. We can see what reply was send by the server.