[Previous] [Contents] [Next]

Lesson 1:
An introduction to TCP/IP sockets and Winsock

What is a socket?
A socket is a connection between two computers in a TCP/IP network. Sockets are used to exchange information such as files, mails, websites etc. Many computer games also use sockets for multiplayer games.

There are two types of sockets, TCP (Transmission Control Protocol) sockets and UDP (User Datagram Protocol) sockets. As you can see, these two types are called protocols. A protocol is a set of rules used to determine the way information is received and sent in a network. Other protocols are often used on top of TCP and UDP, for example, FTP is a protocol for file transfer which uses TCP to communicate with the file server. TCP and UDP themselves are built on top of the IP (Internet Protocol). The difference between these types is that in a TCP socket, the information sent is guaranteed to reach the recepient, this is not the case for UDP sockets, in this case, the information is not guaranteed to reach the recepient at all. Because of this, many UDP applications that uses datagram sockets to send information waits for the recepient to send a reply to check whether the transfer succeded or not.

To connect a socket to another computer, you need to know its IP-address and which port you are going to connect to. An IP-address consists of four numbers between 0 and 255 (although 0 and 255 are reserved) separated by dots. For example, 195.125.13.54 Each computer has 65536 different ports. Some ports are reserved for different protocols. For example, port number 80 is reserved for the HTTP (HyperText Transfer Protocol) protocol and 21 is reserved for FTP (File Transfer Protocol). All the ports under 1024 are reserved for specific protocols and should not be used by other protocols.

What do I need?
All you need is a C/C++ compiler, some basic understanding of networking and knowledge in the C language. A documentation of the winsock functions, structures and constants can be found at: http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winsock/apistart_9g1e.htm

What is Winsock?
Winsock is a networking API for Windows. This API provides functions for sending and receiving data in a network via a protocol, such as TCP/IP. There are several versions of Winsock running on different operating systems, Windows 95 and Windows CE supports Winsock 1.1 while Windows 98, Windows 2000 and Windows NT 4 support the Winsock 2 API. For Windows 95, an upgrade to Winsock 2 is avaliable at: http://www.microsoft.com/windows95/downloads/

[Previous] [Contents] [Next]