0% found this document useful (0 votes)
81 views

Socket Programming

Socket programming allows applications to communicate over a network. A socket is an interface between an application process and the transport layer (network). There are two basic types of socket communication: streams using TCP, which provide a continuous flow of data like a file, and datagrams using UDP, which send discrete packets of data. TCP provides reliable, connection-oriented communication using streams and port numbers, while UDP provides unreliable connectionless datagram transmission. Socket programming abstracts the complexities of the network layers and provides a standardized way for applications to communicate over networks.

Uploaded by

akah
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)
81 views

Socket Programming

Socket programming allows applications to communicate over a network. A socket is an interface between an application process and the transport layer (network). There are two basic types of socket communication: streams using TCP, which provide a continuous flow of data like a file, and datagrams using UDP, which send discrete packets of data. TCP provides reliable, connection-oriented communication using streams and port numbers, while UDP provides unreliable connectionless datagram transmission. Socket programming abstracts the complexities of the network layers and provides a standardized way for applications to communicate over networks.

Uploaded by

akah
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/ 43

SOCKET PROGRAMMING

SOCKET
What is Socket?
 Socket is an interface between an application
process and transport layer(i.e. Network)

 In Unix , a socket is a file descriptor – an integer


associated with an open file.
The Problem
Two Main Issues
Network Addressing
Identifying the Destination
Standard Ports
Connections
Client/Server Concepts
Data Transport
There are two basic types of communication
 Streams (TCP): Computers establish a
connection with each other and read/write data
in a continuous stream of bytes---like a file. This is the
most common.
 Datagrams (UDP): Computers send discrete
packets (or messages) to each other. Each
packet contains a collection of bytes, but each
packet is separate and self-contained.
TCP CHARACTERISTICS
 Connection-oriented

• Two endpoints of a virtual circuit


 Reliable

• Application needs no error checking


 Stream-based

• No predefined blocksize
 Processes identified by port numbers
 Services live at specific ports
UDP CHARACTERISTICS
 Datagram-based

• Connectionless, unreliable, can broadcast


 Applications usually message-based

• No transport-layer retries
• Applications handle (or ignore) errors
 Processes identified by port number
 Services live at specific ports

• Usually below 1024, requiring privilege


SOCKETS
 Both protocols (UDP, TCP) are supported using
"sockets"
• A socket is a file-like object.
• Allows data to be sent and received across the
network like a file.
• But it also includes functions to accept and
establish connections.
• Before two machines can establish a connection,
both must create a socket object.
Why Socket?
 How can I program a network application?
◦ Share data
◦ Send messages

 IPC - Interprocess Communication


Sockets
THE TCP/IP LAYERING MODEL
THE TCP/IP LAYERING MODEL
Socket Description
Layering Makes it Easier
 Application programmer
◦ Doesn’t need to send IP packets
◦ Doesn’t need to send Ethernet frames
◦ Doesn’t need to know how TCP
implements reliability
 Only need a way to pass the data down

◦ Socket is the API to access transport layer


functions.
NETWORK BASICS: PORTS
SOCKET PROGRAMMING IN A
NUTSHELL
 Server creates a socket, binds it to some
well-known port number, and starts
listening.
 Client creates a socket and tries to connect

it to the server (through the above port).


 Server-client exchange some data.
 Close the connection (of course the server

continues to listen for more clients).


MAJOR SYSTEM CALLS
MAJOR SYSTEM CALLS (SUMMARY)
CONNECTIONLESS SERVICES
CONNECTION-ORIENTED SERVICES
Socket Basics
SOCKET FAMILY AND TYPE
Using a Socket
Server Implementation
TCP Server
TCP Server
TCP Server
TCP Server
TCP Server
TCP Server
TCP Server
TCP Server
Partial Reads/Writes
Partial Reads/Writes
UDP : Datagrams
UDP Server
UDP Client
THANK YOU!

You might also like