Introduction to Socket Programming
Pre-requisites
- Ability to read and write programs in C.
- Basic understanding of computer networking.
Course Outline
- General Issues
- Why Sockets?
- Client-Server Model
- Network Timeline Diagrams
- Connections and Associations
- Byte Order
- Port Numbers
- IPv4 and IPv6
- TCP Sockets
- TCP
- Overview
- TCP Socket Functions
- socket Function
- connect Function
- TCP Echo Client
- bind Function
- listen Function
- accept Function
- TCP Echo Server
- Byte Ordering Macros
- TCP Client/Server Example
- UDP Sockets
- UDP Overview
- UDP Socket Functions
- connect Function (UDP)
- Sending Data
- Receiving Data
- UDP Client/Server Example
- Advanced Topics
- The shutdown() function
- The close() function
- Setting socket options
- Local Domain Protocols
- I/O Multiplexing: select() function
- I/O Timeouts
- Broadcasting
- Multicasting
Code Samples
All the code samples here are working programs that are used in the
class to reinforce the lecture notes.
- tcpEchoClient.c
- This application reads text from the user, opens a connection to
a remote computer's echo service, sends the text, reads
the result and prints it out. This program shows all the phases
of TCP socket programming on both the IPv4 and IPv6 protocols.
Suggested Texts
Although the class is fully self contained it is often helpful to have
supporting texts. I recommend the following:
- TCP/IP
Illustrated Volume 1 by W. Richard Stevens
- Provides an excellent overview of the TCP/IP protocol suite
including detailed examples and real world packet traces.
- The Design and Implementation of the FreeBSD Operating
System by McKusick and Neville-Neil
- The reference on the FreeBSD Operating System, the
progenitor of the sockets API and TCP/IP networking. Discusses
the entire system, not just networking and sockets.