This FAQ answers the most commonly-asked questions about Winsock. The bulk of it was written back when mailing lists and news groups were the best ways to find people who knew Winsock deeply, and so drew heavily from those resources. Today, there are better places to ask questions.

This FAQ also contains a repository of Winsock programming information and links useful for all levels of programmers. Please email me if you have any corrections or additions for the list.

If you would like to view this FAQ off-line, you can download a ZIPped version (440 KB) of these pages.

Last updated 2011.02.21 — Revision History

Search the FAQ

You can do a full-text search on the FAQ for any word or phrase.

Beware: The word “Winsock” appears on every page on the site. Adding it to your search buys you nothing.

Contents

Section 0 – Introduction

0.1 –  The Original Introduction
0.2 –  About the Maintainer
0.3 –  Legal Stuff
0.4 –  Mirrors
0.5 –  Where can I ask questions not already in the FAQ?
0.6 –  Is there a mailing list for FAQ updates?
0.7 –  What Windows and Winsock versions does the FAQ cover?
0.8 –  Programming Language Bias
0.9 –  Protocol Bias
0.10 –  Acknowledgements

Section 1 – General Winsock Information

1.1 –  What is Winsock?
1.2 –  What’s the difference between Winsock and TCP/IP?
1.3 –  What does Winsock 2 have that Winsock 1.1 doesn’t?
1.4 –  When is the next rev of the specification due out?
1.5 –  Can Winsock speak { DECNet, IPX/SPX, etc. }?

Section 2 – Issues for New Winsock Programmers

2.1 –  Which sockets API should I target?
2.2 –  Are there any sample apps on the Net?
2.3 –  Do I need to initialize the WSAData structure before calling WSAStartup?
2.4 –  I’m getting link errors when compiling Winsock programs. What’s wrong?
2.5 –  If I write a Winsock program, will I be able to communicate with a Unix Sockets program?
2.6 –  Can I use Winsock with { My Favorite Language }?
2.7 –  Are there any tools available for debugging Winsock programs?
2.8 –  How do I get a readable error message from a Winsock error number?
2.9 –  Winsock keeps returning the error WSAEWOULDBLOCK. What’s wrong with my program?
2.10 –  How can I test my Winsock application without setting up a network?
2.11 –  What’s the proper way to close a TCP socket?
2.12 –  Is it possible to close the connection “abnormally”?
2.13 –  How do I detect when my TCP connection is closed?
2.14 –  How do I detect an abnormal network disconnect?
2.15 –  How can I change the timeout for a Winsock function?
2.16 –  What is peeking (MSG_PEEK), and why is it bad?
2.17 –  What is out-of-band data (MSG_OOB), and why is it bad?
2.18 –  If MSG_PEEK and MSG_OOB are bad, what do I pass for send() and recv()’s flags parameter?

Section 3 – Intermediate Winsock Issues

3.1 –  How do I speak { HTTP, POP3, SMTP, FTP, Telnet, NNTP, etc. } with Winsock?
3.2 –  How can I encrypt my TCP stream with SSL/TLS?
3.3 –  How do I get my computer’s IP address?
3.4 –  What’s the proper way to impose a packet scheme on a stream protocol like TCP?
3.5 –  I’m writing a server. What’s a good network port to use?
3.6 –  What is TCP?
3.7 –  What is UDP?
3.8 –  What is UDP good for?
3.9 –  How do I send a broadcast packet?
3.10 –  Is Winsock thread-safe?
3.11 –  If two threads in an application call recv() on a socket, will they each get the same data?
3.12 –  Is there any way for two threads to be notified when something happens on a socket?
3.13 –  How do I detect if there is an Internet connection?
3.14 –  How can I get the local username?
3.15 –  I’ve heard that asynchronous sockets are unreliable. Is this true?
3.16 –  What is the Nagle algorithm?
3.17 –  When should I turn off the Nagle algorithm?
3.18 –  What is TCP’s sliding window?
3.19 –  What is the silly window syndrome?
3.20 –  What is the delayed ACK algorithm?
3.21 –  What platform should I deploy my server on?

Section 4 – Advanced Winsock Issues

4.1 –  Does Winsock support raw sockets?
4.2 –  How can I capture packets on a LAN with Winsock?
4.3 –  How can I change the contents of a packet?
4.4 –  How can I “ping” another machine?
4.5 –  Is it possible to create sockets that map to a DLL rather than an application?
4.6 –  How can I get access to the {route, ARP, interface, etc.} table?
4.7 –  How do I get the MAC (a.k.a. hardware) address of the local Ethernet adapter?
4.8 –  How many simultaneous sockets can I have open?
4.9 –  What are the “64 sockets” limitations?
4.10 –  How do I make Winsock use a specific network interface?
4.11 –  What do the FIN_WAIT_x, TIME_WAIT, CLOSE_WAIT and other states mean?
4.12 –  What is the { SYN, ACK, FIN, RST } bit?
4.13 –  Is it a bad idea to bind() to a particular port in a client program?
4.14 –  What is the connection backlog?

Section 5 – Resources

5.1 –  Winsock Libraries and Controls
5.2 –  Samples: Tutorial Code
5.3 –  Samples: Useful Code
5.4 –  Other Web Pages
5.5 –  MS Knowledge Base Articles

Section 6 – Examples

6.1 –  Several Basic Winsock Programs
 –  Basic blocking client
 –  Asynchronous client
 –  CAsyncSocket-based client
 –  Basic blocking server
 –  Basic multi-threaded server
 –  Basic select()-based server
6.2 –  Pinging a Host Using Microsoft’s ICMP.DLL
6.3 –  Pinging a Host Using Raw Sockets
6.4 –  How to Pass a Socket Handle in Win32
6.5 –  Getting the Local IP Address
6.6 –  Getting the Network Interface List
6.7 –  How to Get the MAC (a.k.a. “hardware”) Address, NetBIOS method
6.8 –  How to Get the MAC (a.k.a. “hardware”) Address, RPC method
6.9 –  How to Get the MAC (a.k.a. “hardware”) Address, SNMP method
6.10 –  How to Get the Local User Name
6.11 –  How to Packetize a TCP Stream
6.12 –  How to Check for a RAS Connection

Section 7 – Articles

Winsock for the Impatient by Warren Young
Which I/O Strategy Should I Use? by Warren Young
How to Use TCP Effectively by Warren Young
The Lame List by the Winsock Vendor Community
Debugging TCP by Warren Young
The Straight Dope on Packet Sniffers by Warren Young
Winsock’s Compatibility With BSD Sockets by Warren Young
WsControl() Revealed by Tom Sanfilippo
CSocket Considered Harmful by Warren Young
Passing Sockets Between Processes by Warren Young and Frank Schmied
Dealing with Firewalls by Warren Young
Winsock for Non-Windows Systems by Warren Young
The History of Winsock: The Bad Old Days by Warren Young

Section 8 – Book and Software Reviews
Section 9 – Glossary

  Go to my home page