0% found this document useful (0 votes)
53 views18 pages

IFA 307 - Application Programming Interface (Sockets) - Lec6

The document summarizes a lecture on Application Programming Interface (Sockets) for the Semester Ganjil 2018/2019 at the Institut Teknologi Nasional, Fakultas Teknologi Industri, Jurusan Teknik Informatika. The lecture introduces sockets and basic socket programming, with goals of understanding the purpose of sockets and how to implement networking using sockets. It provides an overview of socket programming concepts like TCP vs UDP, addresses, ports, and the basic steps to create a TCP client and server.

Uploaded by

Fikri Haekal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views18 pages

IFA 307 - Application Programming Interface (Sockets) - Lec6

The document summarizes a lecture on Application Programming Interface (Sockets) for the Semester Ganjil 2018/2019 at the Institut Teknologi Nasional, Fakultas Teknologi Industri, Jurusan Teknik Informatika. The lecture introduces sockets and basic socket programming, with goals of understanding the purpose of sockets and how to implement networking using sockets. It provides an overview of socket programming concepts like TCP vs UDP, addresses, ports, and the basic steps to create a TCP client and server.

Uploaded by

Fikri Haekal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Semester Ganjil 2018/2019 , Fakultas Teknologi Industri, Jurusan Teknik Informatika.

Application Programming
Interface (Sockets) IFA 307
Lisa Kristiana S.T., M.T., Ph.D

Institut Teknologi Nasional, Fakultas Teknologi Industri


Jurusan Teknik Informatika,
Program Sarjana Informatika
[email protected]
Lecture Content
• Introduction to socket
• Basic socket programming
Lecture Goal
• Understand the purpose of socket
• Understand how to do ‘networking’ using
socket
Network API
• The place to start when implementing a
network application is the interface exported
by the network, This interface is often called
the network application programming
interface (API).
• The main abstraction of the socket interface,
not surprisingly, is the socket.
Socket
• Sockets are an interface between the
Application and Network layers.
• The TCP/IP layer model, compresses the top 3
OSI layers into one.
• It is commonly used for client and
server interaction. 
Introduction to Socket Programming

• The server executes first and waits to receive.


• The client executes second and sends the first
network packet to the server.
• After initial contact, either the client or the
server is capable of sending and receiving data
The Socket Interface and Features of a TCP
connection

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);

• Step 2: Binding an address and port number


int bind(int socket_file_descriptor, const
struct sockaddr * LocalAddress,
socklen_tAddressLength);

• Step 3: Listen for incoming connections


int listen(int socket_file_descriptor, int
backlog);

• Step 4: Accepting a connection.


int accept (int socket_file_descriptor,
struct sockaddr * ClientAddress,
socklen_t*addrlen);
Outline of a TCP Client
• Step 1: Create a socket : Same as in the server
• Step 2: Binding a socket: This is unnecessary for a client.

• Step 3: Connecting to a Server:


int connect(int socket_file_descriptor, const
struct sockaddr *ServerAddress,socklen_t
AddressLength);

• Step 4: Read and Writing to the socket


int read(int file_descriptor, char *buffer,
size_t buffer_length);
int write(int file_descriptor, const void * buf,
size_t message_length);

• Step 5: Closing the socket


int close(int filedescriptor);
Outline of a client-server network interaction:
Summary of Functions
• Socket creation and destruction:
• socket()
• close()
• shutdown()
• Client:
• connect()
• bind()
• Server:
• accept()
• bind()
• listen()
• Data Transfer:
• send()
• recv()
• write()

You might also like