2.
7 Socket
Programmi
ng:
Creating
Network
Application
s
2018--2019
Network Applications
It consist of a client program and a
server program that communicate
via sockets.
Open applications: Follow a
publicly known protocol (such as
1 HTTP in RFC 2616) and can
There are interoperate between
two types of independently developed client
network and server
Proprietary programs. Use
applications:
applications: 2 a private protocol controlled by
the developer, limiting
interoperability.
Developers must decide whether the
application will use TCP (connection-
2018--2019
oriented, reliable) or UDP
(connectionless, less reliable) for
communication.
1. Implementing protocols 2. Avoiding well-known port
defined by RFCs (Request for numbers when developing
Comments) and using well- proprietary applications.
known port numbers.
3. Introducing UDP and TCP 4. Noting that the code
socket programming using could have been written in
simple applications in Python Java, C, or C++, but Python
3. was chosen for its clarity
and simplicity.
5. Providing additional
resources for readers
interested in client-server
programming in Java or C.
7. 1
2.
ke t
oc in
S m m
g ra
Pro g P
U D
in
2018--2019
User Datagram Protocol (UDP)
is a connectionless protocol that allows data to
be transmitted between devices in a network
without establishing a dedicated connection.
Communication between processes on different
machines occurs by sending messages through
sockets, where each process is like a house and
its socket is a door.
2018--2019
The application runs on the application-layer
side of the socket, and the transport-layer
protocol operates on the outside.
When using UDP, the sending process attaches
a destination address (the recipient's IP address
and port number) to a packet before sending it
through the socket.
This allows the packet to be routed correctly to
the receiving socket, where the receiving
process retrieves and processes it.
2018--2019
The packet also contains the source address (IP
and port) automatically added by the operating
system.
To demonstrate socket programming, we’ll use a
simple client-server application where the client
sends a line of data to the server, which
converts it to uppercase and sends it back.
The client then displays the modified data.
The client-server program for UDP
communication is minimal and will be analyzed
line by line, using the server port number
2018--2019
7. 1
2.
ke t
oc in
S m m
g ra
Pro g
CP
T
in
2018--2019
Transmission Control Protocol (TCP)
is a connection-oriented protocol, unlike UDP,
meaning a handshake is required before data
can be exchanged.
A TCP connection links the client socket to the
server socket, each associated with their
respective IP addresses and port numbers. The
client initiates the connection, and the server
must be ready to accept it by running as a
process and having a welcoming socket.
2018--2019
When the client creates a TCP socket, it specifies
the server's socket address and begins a three-
way handshake to establish the connection.
This process is invisible to the client and server.
Once the handshake is complete, the server
creates a new dedicated socket for
communication with the client.
This connection ensures reliable, ordered data
transfer between the client and server.
2018--2019
The client can both send and receive data
through its socket, while the server does the
same through its connection socket.
The interaction is demonstrated in a simple
client-server application where the client sends
data to the server, which processes and returns
it.
2018--2019
2018--2019
2018--2019
Why does the UDP server need only one
socket, while the TCP server needs two?
The key difference between UDP and TCP lies in
how connections are established and maintained:
UDP is connectionless, meaning there’s no need
to establish a session between the client and
server. The server simply binds to a port and
listens for incoming packets. It uses one socket
for receiving and sending messages, since it
doesn't need to manage a dedicated connection
to each client.
2018--2019
TCP is connection-oriented. It requires the server
to accept incoming connections from clients.
This process involves two steps:
① A listening socket to wait for incoming
connection requests.
② A separate socket for each individual
connection, used for communication with each
client once the connection is established.
Thank You
for
Listening!