Using Winsock

© Copyright 1999 University of New Haven

Obtaining Winsock

The Winsock package consists of 3 files: winsock.h, winsock.lib and winsock.dll.

NOTE: If your compiler and operating system ALREADY have these files, SKIP THIS STEP... DO NOT REPLACE WINSOCK FILES already installed on your computer

If your machine already has the Winsock files, then skip to Domain Names or IP Addresses below.

Click here to download a compressed file, winsock.exe containing files winsock.h and winsock.lib which I have successfully tested with MS Visual C++ 1.0 and Borland C++ 3.0. After downloading file winsock.exe:

  1. Execute file winsock.exe to expand it into files winsock.h and winsock.lib
  2. Move winsock.h to your compiler's include directory (e.g. \MSVC\INCLUDE or \BORLANDC\INCLUDE)
  3. Move winsock.lib to your compiler's library directory (e.g. \MSVC\LIB or \BORLANDC\LIB)
  4. Add winsock to the list of libraries to be searched by the linker, or include it in a project file.
  5. Increase the stack size to at least 16384, either through the Linker options dialog box, or by including STACKSIZE 16384 in a project definitions (.DEF) file.

The third file, winsock.dll, must be available on your local PC. It is not portable, but comes with your TCP/IP package, such as Windows for Workgroups 3.11 TCP/IP, Windows 95, NT or Trumpet Winsock. It should be somewhere in your path, or perhaps in \WINDOWS or \WINDOWS\SYSTEM.

Domain Names or IP Addresses

If you wish to establish a connection to a machine which has an IP address, but not a domain name (e.g. a PC in the CS lab), instead of:

 
     serverip = gethostbyname("charger.newhaven.edu");

you should use:

 
     long ipaddr   = inet_addr("204.60.72.11");
          serverip = gethostbyaddr(&ipaddr, 4, PF_INET);

This situation can arise when you wish to connect to a server running on a Windows PC in the CS lab. The PC's IP address can be found in a MS-DOS environment variable named IP which is displayed by the MS-DOS set command.

General information about Winsock is available at Stardust, a repository for Winsock information.

Home