Bharatiya Vidya Bhavan’s
Sardar Patel Institute of Technology
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai-400058-India
(Autonomous College Affiliated to University of Mumbai)
Department of Electronics and Telecommunication
Course code EC 307 Computer Communication Network 2022.23
Name: Gaurang Gawas UID: 2021201071
EXPERIMENT-5
Aim: Client server model using socket programming.
Apparatus (Software): Open-source software
Procedure: To do this EXPERIMENT- follows these steps:
The steps involved in establishing a TCP socket on the server side are as follows:
1. Create a socket with the socket () function;
2. Bind the socket to an address using the bind () function;
3. Listen for connections with the listen () function;
4. Accept a connection with the accept () function system call.
Bind the socket to server address. Wait until datagram packet arrives from client.
UDP Client Side :
1. Create UDP socket.
2. Send message to server.
3. Wait until response from server is received.
4. Process reply and go back to step 2, if necessary.
5. Close socket descriptor and exit.
Theory:
Socket programming is a way of connecting two nodes on a network to communicate with each
other. One socket(node) listens on a particular port at an IP, while other socket reaches out to
the other to form a connection.
Most of the Net Applications use the Client-Server architecture, which refers to two processes
or two applications that communicate with each other to exchange some information. One of
the two processes acts as a client process, and another process acts as a server.
Client Process
This is the process, which typically makes a request for information. After getting the
response, this process may terminate or may do some other processing.
Example, Internet Browser works as a client application, which sends a request to the Web
Server to get one HTML webpage.
Server Process
This is the process which takes a request from the clients. After getting a request from the
client, this process will perform the required processing, gather the requested information, and
send it to the requestor client. Once done, it becomes ready to serve another client. Server
processes are always alert and ready to serve incoming requests.
Example − Web Server keeps waiting for requests from Internet Browsers and as soon as it
gets any request from a browser, it picks up a requested HTML page and sends it back to
that Browser.
Note that the client needs to know the address of the server, but the server does not need to
know the address or even the existence of the client prior to the connection being established.
Once a connection is established, both sides can send and receive information.
Code:
1. TCP:
a. Server
b. Client
2. UDP:
a. Server
b. Client
Demonstration: Output
1. TCP:
2. UDP:
Interpretation:
1. TCP:
Server is running on localhost 3000. When a TCP socket is used , Connection is
established between server and client before transmission and then
communication takes place .
2. UDP:
● Server and client both are now using UDP protocol.
● The message is stored in the sender buffer in the form of bytes and these
bytes are then converted into a datagram packet by the client.
● Client then sends these packets to server ip address using datagram socket
without establishing a connection.
● Server collects these packets and responds to client requests in a similar way
Conclusion:
● Used java programming language to create socket between client and server.
● TCP protocol requires connection between client and server whereas UDP
sockets send data in form of packets without dedicated connection.
● TCP data is reliable, ordered and error-checked delivery of data is done over a
network.
● UDP data transmission is fast and connectionless mostly used in real-time
applications like video conferencing, online gaming.