Windows Sockets Programming

This page is designed to give the programmer enough information to know where to look to get the actual information.

What is Windows Sockets?

Windows Sockets, or Winsock, is a .DLL which allows applications to talk over a network, usually the Internet. The .DLL is usually called WINSOCK.DLL.

Where do I get Windows Sockets?

Unlike all other .DLLs, there isn't an official WINSOCK.DLL in the sense that there is say a 'common dialog' COMMDLG.DLL or a 'control 3d' CTL3DV2.DLL. When you get WINSOCK, you get it from a particular vendor. Each different version is slightly different in terms of how it is configured, but once it is configured properly each .DLL should have the same functions and properly written applications will work with whatever Winsock you are using.

Popular Winsocks are:

Trumpet Winsock
This Winsock is shareware. It has the ability to talk over an Ethernet board or over a modem to an Internet provider, but it can't do both simultaneously. Note that if you don't have a network card or an Internet provider account you can still write and test programs running both the client and server on your machine, provided you have a serial port. You can FTP the old unlimited Trumpet from ftp://ftp.demon.co.uk/.d3/ibmpc/win3/winsock/stacks/trumpwsk/twsk20b.zip. For Trumpet-specific info, check out the newsgroup alt.winsock.trumpet. The Trumpet WWW site is in Australia and I have had difficulty getting into it. You can also get Trumpet from Stroud's CWSApps List.

There are two version of Trumpet. The 1.x version can connect via modem with SLIP, the 2.x versions can use SLIP or PPP. 2.0b never expired.

Wolverine
This Winsock is freeware. It only works with Windows for Workgroups, and only over an Ethernet. It was written by Microsoft. You can FTP the files from the ftp://ftp.microsoft.com/peropsys/windows/public/tcpip/ directory.

FTP Software's Winsock
This Winsock is a commercial product. It provides a way to write DOS programs which talk over networks as well. It only works over Ethernet, Token-Ring, SLIP, PPP, and X.25 (as well as some other little used topologies). I've only used it over Ethernet.

Windows 95 Winsock
This Winsock comes with Windows 95. It works over the Modem or most network cards. See Windows95.com Internet TCP/IP Connectivity for more information.

Windows NT Winsock
This Winsock comes included with Windows NT. It can talk over an Ethernet board and over a modem simultaneously. For instructions on connecting to the Internet with your modem, see Remote Access Services. Another source of information on NT winsock is The Windows NT Internet FAQ 1 of 2 and The Windows NT Internet FAQ 2 of 2.

The biggest problem with having so many different kinds of Winsocks is that you will almost certainly have problems if you have more than one WINSOCK.DLL on your system. Developers need to keep and run multiple versions for testing and users seem to get different versions from each Internet provider they sign up for. There is no good solution to this problem, as far as I know.

What is TCP/IP?

TCP/IP is the Internet Protocol. Most Winsocks speak TCP/IP.

If you are on a NetWare lan, your LAN might speak IPX/SPX as its native protocol. That doesn't matter, because in most cases TCP/IP and IPX/SPX can live on the same Ethernet in harmony, not even being aware of the other's existance. To get this to work with Trumpet you will have to alter your NET.CFG.

If you are connecting to the Internet with a modem, you are probably used to the way that a communications terminal program, like Windows Terminal, dials a phone number and then each character sent over the modem reaches the other 'end', where the other end is some program running on the computer in charge of the modem at the other end.

Network protocols don't work like this. On the Internet, each machine is given an address which is four numbers, such as 1.2.3.4. You send data in chunks called 'packets' and you tell TCP/IP the address of the machine that you want to get the data, and the 16 bit 'socket number' of the program running on that machine that you want to get the data. TCP/IP sends your packet and provides a way for the other program to get a response back to you.

Frequently asked Questions:

Are there any books on Winsock?
There are many. The first one was called Programming Winsock by Arthur Dumas, ISBN: 0-672-30594-1, $35.00 US I didn't like it. All of the examples were in Visual C++, and I found typos. It also doesn't have a lot of winsock-specific information that isn't provided with the WINSOCK.HLP file. It is, however, the only book which exclusively covers Winsock. I think it would be a good book if you didn't know anything about TCP/IP programming but knew Windows and wanted to learn.
There are some other books out or on the way which discuss Winsock. I don't have a full list here, so if you wrote a book and you don't see it send me a note. One book that is very interesting is Windows Sockets Network Programming by Bob Quinn and David K. Shute.

Where can I get example source code?

  • For some Winsock code agood collection is at VIJAY MUKHI'S TECHNOLOGY CORNUCOPIA
  • WinVN NNTP Newsreader: ftp://ftp.ksc.nasa.gov/pub/winvn/source/current/winvn
    (WinVN is an excellent newsreader, many people consider it the best. It can be compiled into both 16 bit and 32 bit versions.)
  • WS_FTP FTP client: ftp://ftp.stardust.com/pub/winsock/version1/sample/wsftpsrc.zip
    (WS_FTP is an excellent graphical FTP, better than commercial FTPs.)
  • Finger client and server: ftp://ftp.mv.com/pub/ddj/1993/1993.02/1993-feb.zip
    (Within this archive is a file called sockets.asc, basically a source code listing for 'both' a finger client and finger server. From the Feb '93 Doctor Dobbs magazine)
  • WWW server: ftp://ftp.cdrom.com/.22/cica/win3/winsock/serweb03.zip
    (Requires MFC)
  • MUD server: http://www.goodnet.com/~esnible/mercwsrc.zip
    (This is the Merc 2.2 MUD ported from Unix to the PC. Requires a 32 bit compiler. To run this source code you must also get the executable .zips, mercw32.zip and mercw32a.zip. Very poor Windows port, but the only Winsock-based MUD server I have found).
  • WormHole: A simple file transfer utility (16- and 32-bit) (From Microsoft)
  • What about Telnet?
    The source for NCSA telnet is out there, but it doesn't work with Winsock. I believe it writes directly to packet drivers.
    What about a WWW browser?
    If you are an education institution you can get the source code for NCSA Mosaic. There are also WWW custom controls available, from Microsoft and others, that you can use in your own programs.
    POP3 mail client?
    Developing a POP3 client is an ongoing series in Doctor Dobbs. To download the source code, go to ftp://ftp.mv.com/pub/ddj and get the code from the 1995.04, 1995.05, and 1995.06 directories.
    Ping?
    Ping is a non-standard extension to the Winsock 1.1. For a basic Ping that works with some Winsocks, see Chapter 16 of the book Windows Sockets Network Programming.

    For source code to an actual Winsock .DLL, there is the Waterloo Winsock:
    ftp://ftp.stardust.com/pub/winsock/version1/sample/watsock.zip
    I haven't looked at this in a while. Waterloo made a free TCP/IP stack for DOS before the days of Winsock. I believe this either sat on top of their TCP/IP stack for DOS or possibly on top of a packet driver. It is a pretty old program, and it is getting scarce.

    Where is Winsock discussed?
    On Usenet, in alt.winsock.programming and comp.os.ms-windows.programmer.tools.winsock. There are also mailing lists for people designing Winsock 2.0, see http://www.stardust.com/wsresource/winsock/wslists.html for more details.

    Where can I get Winsock programming information on the World Wide Web?
    http://www.stardust.com/welcome.html also has some good information.
    http://www.cis.ohio-state.edu/hypertext/faq/usenet/ibmpc-tcp-ip-faq/part1/faq.html is the comp.protocols.tcp-ip.ibmpc Frequently Asked Questions (FAQ)
    ftp://SunSite.UNC.EDU/pub/micro/pc-stuff/ms-windows/winsock/FAQ is a sort of Winsock specification FAQ.
    BSD Sockets: A Quick and Dirty Primer

    Where can I get Windows sockets applications in general?
    Stroud's Consummate Winsock, http://cws.wilmington.net, is a good place to find out about the latest Winsock applications.

    How come I am getting linker errors when I compile?
    A lot of WINSOCK.LIB files floating around have lower case symbols when they should have upper case symbols. Often, if you tell your compiler you don't want a 'case sensative link' or 'case sensitive import' you will have better luck.

    Are there C++ class libraries for Winsock? There are. A good resource is Winsock Development Tools . Visual C++ has included libraries since version 2.1. Borland C++ has them in version 5.0. For OWL users, there is a class called OWLSock. Many books also develop socket libraries.

    What about all of these new Microsoft APIs
    Microsoft has many new layers above Winsock which are supposed to make programming easier and lock you into their libaries. Currently you can get something called The ActiveX SDK which includes all kinds of stuff. Basically, Microsoft's plan is to add a bunch of new Win32 APIs and OLE/COM controls so that you can do FTP and WWW stuff without Winsock.

    What about Java? How is that related to Winsock? Java is a new C++-like language. It allows programs to load off the Internet and run inside your Web Browser. See Gamelan for more info.

    What is WSOCK32.DLL? also, How do I get Trumpet to work with Windows 95?
    WSOCK32.DLL is a thunk to let Win32s programs use WINSOCK.DLL. It comes with Win32s, I believe. You need this if you are running a 32 bit program with Trumpet or other 16 bit Winsock. It doesn't do anything except let Win32s programs call Winsock. If you are running NT or Win95, you want to use the built-in networking, not a second TCP/IP stack. Note: The Win95 preview doesn't work with Dynamic SLIP as far as anyone knows. So if your provider gives you that, you need to get changed to a permanent IP number unless there is a better Win95 soon.

    What is multicast? Multicasting allows one source to send IP packets to many clients efficently. Newer Winsock stacks support this, the network routers may need to be updated to support this feature. See MBone Information Web.

    Ed Snible's home page
    N© This page is in the public domain.