0% found this document useful (0 votes)
30 views32 pages

10 - L10-Client Server Programming

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

10 - L10-Client Server Programming

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

CS302.

3
Wireless Technologies and
Network Programming
Lecture 10 – Client Server Architecture and Sockets

Chamara Disanayake
Department of Network and Security
Network Communication

• Required Components
• Sender and a Receiver
• Message
• Protocols (Rules)
• Considerations
• How they know each other and how to create a unique communication
between them
• Because many nodes, many communication streams
• How they know what to do/what is requested/How to request

2
Unique Communication

• Identify each other


• Addressing methods
• Each address method is used in different layers

3
Addressing Formats

• Each layer use their specific addressing in directing the


communication between the end points.

Two Versions used


• IPv4
• IPv6

4
Addressing

• Port Addresses and Specific Addresses

5
Addressing with Layers

• Most of the times, all addressing schemas are used in communication

6
Network Processes in the Communication

• Two remote application processes can communicate mainly in two


different fashions:
• Peer-to-peer: Both remote processes are executing at same level and they
exchange data using some shared resource.
• Client-Server: One remote process acts as a Client and requests some
resource from another application process acting as Server.
• In client-server model, any process can act as Server or Client. It is not the
type of machine, size of the machine, or its computing power which makes it
server; it is the ability of serving request that makes a machine a server.

• Normally the server waiting for client to request the service and any number
of clients can use the service in the server.

7
Communication Method

• In client-server communications, two fundamental mechanisms used


to enable interaction between distributed systems.
• Sockets
• Remote Procedure Calls (RPC)
• Both mechanisms are essential tools in networking, with sockets offering fine-
grained control and RPCs providing ease of use for distributed computing tasks.
• With the advanced requirement of network communication, new methods
are invented and used in current network applications.
• Web Socket
• REST
• gRPC

8
Sockets

• A socket is one endpoint of a two-way communication link between


two programs running on the network.

A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be
sent to. An endpoint is a combination of an IP address and a port number
Example 192.248.8.97:53
9
Communication between sockets

• When the request is reached to


server, it is served.
• It can either be an information
sharing or resource request.
• The server response is sent to the
client to client’s program referring
the client node address and socket
address

10
Remote Procedure Calls (RPC)

• In distributed computing, a Remote Procedure Call


(RPC) is when a computer program causes a
procedure (subroutine) to execute in a different
address space (commonly on another computer on
a shared network)

• RPC uses the client-server model. The requesting program is a client and the service
providing program is the server. Like a regular or local procedure call, an RPC is a
synchronous operation requiring the requesting program to be suspended until the
results of the remote procedure are returned.
• However, the use of lightweight processes or threads that share the same address
space allows multiple RPCs to be performed concurrently.
11
Communication Flow
5 components are involved
in sending a message from
client to server:-
• Client
• Client stub
• RPC protocol
• Server stub
• Server

A stub in distributed computing is a piece of code that converts parameters passed between client and server during
a remote procedure call. The main idea of an RPC is to allow a local computer to remotely call procedures on a
different computer

12
Comparison of Sockets vs RPCs

Feature Sockets Remote Procedure Calls (RPCs)


Low-level; requires manual handling of data High-level; abstracts network
Level of Abstraction
transmission complexities
Requires detailed coding for communication Simplifies interaction with remote
Ease of Use
logic services
Communication Type Data streams Function/procedure invocation
Use Cases Real-time apps like chat or gaming Distributed systems, microservices

13
Justify the Theories

• How you can justify the communication


• Use OS tools and software to check the connections and related network
parameters in the communication flow
• Command prompt with telnet enabled, wireshark to capture packets
• Use Command prompt to connect to a server
• Well know website with port 80
• SMTP server with port 25
• Enable telnet command in the command prompt
• Establish the connection with telnet [website_address] port_number

14
Software Tools

• You need to have better understanding of the software tools available


before you create your own application.
• OS tools
• Windows : Command prompt with telnet enabled
Command Format
telnet <server_name/ip> <port_number>

• Third party tools


• Wireshark : Analyze the packets in the communication

15
Observe the Outcome

16
Developing Network Applications

17
Identify the Requirements

• You may need to create two processes in network nodes and enable
network communication between the remote processes.
• Server-side application
• Cater the service to the clients
• Runs on well known addresses (logical and port addresses) which are not
affecting the current communication
• Binds a socket to its end of the connection
.
• A socket is one endpoint of a two-way communication link
between 2 programs running on the network.
• A socket is bound to a port number so that the TCP layer
can identify the application to which the data is to be sent.
• It is similar to the idea of plugging the two together with a
cable

18
Client-Side Requirements

• Client-side application
• Initiate network communication with the server side using the socket bound to
the process in the server side.
• Capability communicate with Application-level protocols
• Converting/present the communication in a user-friendly interface with high
human readability

19
Socket Types

• States in server and client nodes

20
TCP

• For Reliability /Connection Oriented communication used for


applications which needs those qualities

21
UDP

• Fast, Real-time service for applications which needs those


requirements
• Real time communication, DNS

22
State Transition in Socket Programs

• Different Status of Server and the Client

23
States and Usage

• States in the Server


• Create
• Create socket with domain, type and protocol
• Bind
• After creation of the socket, bind function binds the socket to the address and port
number.
• Listen
• It puts the server socket in a passive mode, where it waits for the client to approach the
server to make a connection.
• Accept
• It extracts the first connection request on the queue of pending connections for the
listening socket, sockfd, creates a new connected socket, and returns a new file
descriptor referring to that socket. At this point, connection is established between client
and server, and they are ready to transfer data.

24
State and Usage in Client-Side

• States in the Client


• Create
• Exactly as the server-side
• Connect
• The connect() system call connects the socket referred to by the file descriptor
sockfd to the address specified by addr. Server’s address and port is specified in
addr.

25
Socket Programming

• Socket API is available for many languages on many platforms:


• C/C++, Java, Perl, Python (A common language that networking professionals
will encounter in their careers
• Socket Programs written in any language and running on any platform can
communicate with each other!
• Writing communicating programs in different languages is a good exercise

26
Example Codes C/C++

• Server-side codes

https://www.geeksforgeeks.org/socket-programming-cc/

27
Create Client Side

28
Example Java

• Server-side communication

29
Java Example

• Client-side Code

30
Python Code

• Server running on local IO with port 12345 and client from the same
machine access it with TCP

https://www.tutorialspoint.com/python/python_networking.htm 31
Selecting Suitable Language

• Identify the SWOT


• Knowledge and experience
• Motivation to learn
• Opportunities
• Languages commonly used
• C/C++
• Java
• Python
• Perl

32

You might also like