IFA 307 - Application Programming Interface (Sockets) - Lec6
IFA 307 - Application Programming Interface (Sockets) - Lec6
Application Programming
Interface (Sockets) IFA 307
Lisa Kristiana S.T., M.T., Ph.D
The Internet does not strictly obey the OSI model but rather
merges several of the protocols layers together
Where is the socket programming interface in
relation to the protocol stack?
Features of a TCP connection:
• Connection Oriented
• Reliability
1. Handles lost packets
2. Handles packet sequencing
3. Handles duplicated packets
• Full Duplex
• Flow Control
• Congestion Control
TCP versus UDP as a Transport Layer Protocol
Address Structures, Ports, Address
conversion functions
• Overview of IP4 addresses
– IP4 addresses are 32 bits long
– each host on the Internet has a unique IP address.
• Ports:
– Sockets are UNIQUELY identified by Internet address,
end-to-end protocol, and port number.
– a socket is first created it is vital to match it with a valid
IP address and a port number.
– Ports are software objects to multiplex data between
different applications
Port (1)
Port (2)
• Ports 0 – 1023, are reserved and servers or
clients that you create will not be able to bind
to these ports unless you have root privilege.
• Ports 1024 – 65535 are available for use by
your programs, but beware other network
applications maybe running and using these
port numbers.
Address Structures
• Socket functions like connect(), accept(), and bind() require
the use of specifically defined address structures to hold IP
address information, port number, and protocol type.
• The difficulty is that you can use sockets to program
network applications using different protocols. For example,
IP4, IP6, Unix local, etc.
• struct sockaddr:
– struct sockaddr_in (IP4, think of in as internet)
– struct sockaddr_in6 (IP6)
– struct sockaddr_un (Unix local)
– struct sockaddr_dl (Data link)
Outline of a TCP Server
• Step 1: Creating a socket:
int socket(int family, int type, int
protocol);