SlideShare a Scribd company logo
1 of 2
Kamran Ashraf
MSCs 1st Semester
13-NTU-4009 National Textile University Page 1
“APPLICATION PROGRAMMING INTERFACE”
In General network applications have two parts simultaneously, application for interaction with
users and protocol for communication. Network protocols are part of the operating system in
most computer systems. “Application programming interface (API)” is the interface provided by
the OS to use the network. API’s can be independently written for each OS and can also be
ported to other OS, that’s why few API’s like Socket interface became part of nearly all
operating systems. Socket interface was defined in unix by berkeley distribution. It was then
ported to other operating systems which made easier for developers to make applications for
different operating systems.
Conceptually socket is used by the programmer to send/receive data on the network. It is
recognized by IP and port number. Main operation of interface can be explained as:
 Creating the socket
 Socket attachment to network
 Send/Receive through the socket
 Close the socket
Typical operations of client application:
• Socket creation
• Resolve server IP and port number
• Connection to the server
• Read/Write data through socket
• Close the socket
Typical operations of server application:
• Socket creation
• Binding IP and port number to socket
• Listen how many client requests pending
• Accept connection from client
• Read/Write data through socket
• Close the socket
Kamran Ashraf
MSCs 1st Semester
13-NTU-4009 National Textile University Page 2
To create a socket we use following operation on both client and server:
• “int socket(int domain, int type, int protocol)”
o Operation was designed the way any protocol suite can be used
o Returns a handler which identifies the socket
o Domain argument indicates protocol family to be used
 i.e. “PF_INET” is used for internet family
o Type argument denotes communication type
 i.e. “SOCK STREAM” is used for reliable byte stream
o Protocol argument indicates particular protocol to be used
 Can be left unspecified as combination of previous arguments indicates
TCP protocol
To establish connection on server we use following:
• “int bind(int socket, struct sockaddr *address, int addr len)”
o Binds IP and port number to socket
o i.e. Port 80 is commonly used by web servers
• “int listen(int socket, int backlog)”
o Listens how many client requests pending
• “int accept(int socket, struct sockaddr *address, int *addr len)”
o Blocks the whole process until new connection is established
o Returns a new socket for established connection
To establish the client connection we use following:
• “int connect(int socket, struct sockaddr *address, int addr len)”
o Only address of remote participant is given in practice
o OS selects any un-used port for connection
To send/receive data application invokes following operation:
• “int send(int socket, char *message, int msg len, int flags)”
o Sends message through connected socket
• “int recv(int socket, char *buffer, int buf len, int flags)”
o Receives message through connected socket
To close the socket we use:
• “Int close (int socket)”

More Related Content

What's hot

Access control list [1]
Access control list [1]Access control list [1]
Access control list [1]Summit Bisht
 
Network testing and debugging
Network testing and debuggingNetwork testing and debugging
Network testing and debuggingSADEED AMEEN
 
Network testing course
Network testing courseNetwork testing course
Network testing coursetcpipguru
 
PMKID ATTACK!!
PMKID ATTACK!!PMKID ATTACK!!
PMKID ATTACK!!Mihir Shah
 
WIFI MODEM Part-22
WIFI MODEM Part-22WIFI MODEM Part-22
WIFI MODEM Part-22Techvilla
 
Exploration lan switching_chapter7
Exploration lan switching_chapter7Exploration lan switching_chapter7
Exploration lan switching_chapter7robertoxe
 
WebRTC Introduction & Basics
WebRTC Introduction & BasicsWebRTC Introduction & Basics
WebRTC Introduction & BasicsMuhammad Ali
 
Communication Mechanisms, Past, Present & Future
Communication Mechanisms, Past, Present & FutureCommunication Mechanisms, Past, Present & Future
Communication Mechanisms, Past, Present & FutureMuhammad Ali
 
MITM Attacks with Ettercap : TTU CyberEagles Club
MITM Attacks with Ettercap : TTU CyberEagles ClubMITM Attacks with Ettercap : TTU CyberEagles Club
MITM Attacks with Ettercap : TTU CyberEagles ClubShritesh Bhattarai
 
Cisco discovery d homesb module 5 - v.4 in english.
Cisco discovery   d homesb module 5 - v.4 in english.Cisco discovery   d homesb module 5 - v.4 in english.
Cisco discovery d homesb module 5 - v.4 in english.igede tirtanata
 
Step by Step guide to set up a simple network in Packet Tracer
Step by Step guide to set up a simple network in Packet TracerStep by Step guide to set up a simple network in Packet Tracer
Step by Step guide to set up a simple network in Packet TracerSorath Asnani
 

What's hot (20)

Access control list [1]
Access control list [1]Access control list [1]
Access control list [1]
 
Network testing and debugging
Network testing and debuggingNetwork testing and debugging
Network testing and debugging
 
Network testing course
Network testing courseNetwork testing course
Network testing course
 
Majd
MajdMajd
Majd
 
PMKID ATTACK!!
PMKID ATTACK!!PMKID ATTACK!!
PMKID ATTACK!!
 
WIFI MODEM Part-22
WIFI MODEM Part-22WIFI MODEM Part-22
WIFI MODEM Part-22
 
Exploration lan switching_chapter7
Exploration lan switching_chapter7Exploration lan switching_chapter7
Exploration lan switching_chapter7
 
WebRTC Introduction & Basics
WebRTC Introduction & BasicsWebRTC Introduction & Basics
WebRTC Introduction & Basics
 
Communication Mechanisms, Past, Present & Future
Communication Mechanisms, Past, Present & FutureCommunication Mechanisms, Past, Present & Future
Communication Mechanisms, Past, Present & Future
 
Ip address.
Ip address.Ip address.
Ip address.
 
MITM Attacks with Ettercap : TTU CyberEagles Club
MITM Attacks with Ettercap : TTU CyberEagles ClubMITM Attacks with Ettercap : TTU CyberEagles Club
MITM Attacks with Ettercap : TTU CyberEagles Club
 
IP Security
IP SecurityIP Security
IP Security
 
Ip security
Ip security Ip security
Ip security
 
Ettercap
EttercapEttercap
Ettercap
 
Bettercap
BettercapBettercap
Bettercap
 
Cisco discovery d homesb module 5 - v.4 in english.
Cisco discovery   d homesb module 5 - v.4 in english.Cisco discovery   d homesb module 5 - v.4 in english.
Cisco discovery d homesb module 5 - v.4 in english.
 
Zigbee Basics
Zigbee BasicsZigbee Basics
Zigbee Basics
 
How to make a simple application on packet tracer
How to make a simple application on packet tracerHow to make a simple application on packet tracer
How to make a simple application on packet tracer
 
Sockets
Sockets Sockets
Sockets
 
Step by Step guide to set up a simple network in Packet Tracer
Step by Step guide to set up a simple network in Packet TracerStep by Step guide to set up a simple network in Packet Tracer
Step by Step guide to set up a simple network in Packet Tracer
 

Similar to Application programming interface sockets

Client server chat application
Client server chat applicationClient server chat application
Client server chat applicationSamsil Arefin
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxRockyBhai46825
 
Simple chat room using python
Simple chat room using pythonSimple chat room using python
Simple chat room using pythonVISHAL VERMA
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxssuser23035c
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project ReportKavita Sharma
 
+ Network Programming.pdf
+ Network Programming.pdf+ Network Programming.pdf
+ Network Programming.pdfOluwafolakeOjo
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Socket Programming
Socket ProgrammingSocket Programming
Socket ProgrammingCEC Landran
 
Socket Programming by Rajkumar Buyya
Socket Programming by Rajkumar BuyyaSocket Programming by Rajkumar Buyya
Socket Programming by Rajkumar BuyyaiDhawalVaja
 
OOP Lecture 24-Network Programming-Part1.pptx
OOP Lecture 24-Network Programming-Part1.pptxOOP Lecture 24-Network Programming-Part1.pptx
OOP Lecture 24-Network Programming-Part1.pptxTanzila Kehkashan
 
Java Network Programming.pptx
Java Network Programming.pptxJava Network Programming.pptx
Java Network Programming.pptxRoshniSundrani
 

Similar to Application programming interface sockets (20)

A.java
A.javaA.java
A.java
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Socket Programming w/ C# - IK
Socket Programming w/ C# - IKSocket Programming w/ C# - IK
Socket Programming w/ C# - IK
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Simple chat room using python
Simple chat room using pythonSimple chat room using python
Simple chat room using python
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptx
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
 
Socket programming
Socket programmingSocket programming
Socket programming
 
+ Network Programming.pdf
+ Network Programming.pdf+ Network Programming.pdf
+ Network Programming.pdf
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Socket Programming by Rajkumar Buyya
Socket Programming by Rajkumar BuyyaSocket Programming by Rajkumar Buyya
Socket Programming by Rajkumar Buyya
 
Network Programming Assignment Help
Network Programming Assignment HelpNetwork Programming Assignment Help
Network Programming Assignment Help
 
OOP Lecture 24-Network Programming-Part1.pptx
OOP Lecture 24-Network Programming-Part1.pptxOOP Lecture 24-Network Programming-Part1.pptx
OOP Lecture 24-Network Programming-Part1.pptx
 
Java Network Programming.pptx
Java Network Programming.pptxJava Network Programming.pptx
Java Network Programming.pptx
 

More from Kamran Ashraf

The Maximum Subarray Problem
The Maximum Subarray ProblemThe Maximum Subarray Problem
The Maximum Subarray ProblemKamran Ashraf
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous ComputingKamran Ashraf
 
Error Detection types
Error Detection typesError Detection types
Error Detection typesKamran Ashraf
 
Graphic Processing Unit
Graphic Processing UnitGraphic Processing Unit
Graphic Processing UnitKamran Ashraf
 
INSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISMINSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISMKamran Ashraf
 

More from Kamran Ashraf (6)

The Maximum Subarray Problem
The Maximum Subarray ProblemThe Maximum Subarray Problem
The Maximum Subarray Problem
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous Computing
 
Error Detection types
Error Detection typesError Detection types
Error Detection types
 
VIRTUAL MEMORY
VIRTUAL MEMORYVIRTUAL MEMORY
VIRTUAL MEMORY
 
Graphic Processing Unit
Graphic Processing UnitGraphic Processing Unit
Graphic Processing Unit
 
INSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISMINSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISM
 

Application programming interface sockets

  • 1. Kamran Ashraf MSCs 1st Semester 13-NTU-4009 National Textile University Page 1 “APPLICATION PROGRAMMING INTERFACE” In General network applications have two parts simultaneously, application for interaction with users and protocol for communication. Network protocols are part of the operating system in most computer systems. “Application programming interface (API)” is the interface provided by the OS to use the network. API’s can be independently written for each OS and can also be ported to other OS, that’s why few API’s like Socket interface became part of nearly all operating systems. Socket interface was defined in unix by berkeley distribution. It was then ported to other operating systems which made easier for developers to make applications for different operating systems. Conceptually socket is used by the programmer to send/receive data on the network. It is recognized by IP and port number. Main operation of interface can be explained as:  Creating the socket  Socket attachment to network  Send/Receive through the socket  Close the socket Typical operations of client application: • Socket creation • Resolve server IP and port number • Connection to the server • Read/Write data through socket • Close the socket Typical operations of server application: • Socket creation • Binding IP and port number to socket • Listen how many client requests pending • Accept connection from client • Read/Write data through socket • Close the socket
  • 2. Kamran Ashraf MSCs 1st Semester 13-NTU-4009 National Textile University Page 2 To create a socket we use following operation on both client and server: • “int socket(int domain, int type, int protocol)” o Operation was designed the way any protocol suite can be used o Returns a handler which identifies the socket o Domain argument indicates protocol family to be used  i.e. “PF_INET” is used for internet family o Type argument denotes communication type  i.e. “SOCK STREAM” is used for reliable byte stream o Protocol argument indicates particular protocol to be used  Can be left unspecified as combination of previous arguments indicates TCP protocol To establish connection on server we use following: • “int bind(int socket, struct sockaddr *address, int addr len)” o Binds IP and port number to socket o i.e. Port 80 is commonly used by web servers • “int listen(int socket, int backlog)” o Listens how many client requests pending • “int accept(int socket, struct sockaddr *address, int *addr len)” o Blocks the whole process until new connection is established o Returns a new socket for established connection To establish the client connection we use following: • “int connect(int socket, struct sockaddr *address, int addr len)” o Only address of remote participant is given in practice o OS selects any un-used port for connection To send/receive data application invokes following operation: • “int send(int socket, char *message, int msg len, int flags)” o Sends message through connected socket • “int recv(int socket, char *buffer, int buf len, int flags)” o Receives message through connected socket To close the socket we use: • “Int close (int socket)”