Socket Programming in C/C++ c Mani Radhakrishnan and Jon Solworth September 24, 2004
c Mani Radhakrishnan and Jon Solworth
Socket Programming in C/C++
sockets
Contact Info
Mani Radhakrishnan Office 4224 SEL email mradhakr @ cs . uic . edu Office Hours Tuesday 1 - 4 PM
c Mani Radhakrishnan and Jon Solworth
Socket Programming in C/C++
sockets
TCP UDP
Introduction
Sockets are a protocol independent method of creating a connection between processes. Sockets can be either connection based or connectionless: Is a connection established before communication or does each packet describe the destination? packet based or streams based: Are there message boundaries or is it one stream? reliable or unreliable. Can messages be lost, duplicated, reordered, or corrupted?
c Mani Radhakrishnan and Jon Solworth
Socket Programming in C/C++
sockets
TCP UDP
Socket characteristics
Socket are characterized by their domain, type and transport protocol. Common domains are: AF UNIX: address format is UNIX pathname AF INET: address format is host and port number Common types are: virtual circuit: received in order transmitted and reliably datagram: arbitrary order, unreliable
c Mani Radhakrishnan and Jon Solworth
Socket Programming in C/C++
sockets
TCP UDP
Socket characteristics (cont’d)
Each socket type has one or more protocols. Ex: TCP/IP (virtual circuits) UDP (datagram) Use of sockets: Connection–based sockets communicate client-server: the server waits for a connection from the client Connectionless sockets are peer-to-peer: each process is symmetric.
c Mani Radhakrishnan and Jon Solworth
Socket Programming in C/C++
sockets
TCP UDP
Socket APIs socket: creates a socket of a given domain, type, protocol (buy a phone) bind: assigns a name to the socket (get a telephone number) listen: specifies the number of pending connections that can be queued for a server socket. (call waiting