0% found this document useful (0 votes)
57 views2 pages

Socket Programming Lab Guide

Uploaded by

Disha Deshmukh
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)
57 views2 pages

Socket Programming Lab Guide

Uploaded by

Disha Deshmukh
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

Experiment No.

02

Aim: Network Socket Programming

Objective: the objective of this experiment is to make students acquainted with socket
programming. And make them accustomed with applications executing on top of these sockets.
Outcomes:After completion of the lab students will be able to
[1] Proficiently complete the Socket programming.
[2] Establish a process to process communication.
[3] Understand the Client-Server paradigm.
Theory: A Socket serves as a connection end point for process-to-process delivery. It consists of
Port Number and IP Address. The detailed working of the socket is mentioned in the diagram
below.

Fig.1. Working of Socket on Server and Client Side

P.T.O.
Experiment No. 02

Requirements:
1. Unix based system on machine.
2. Python/Java/C language compiler/interpreter should be intstalled.

Steps to run a socket program:


1. Open a terminal and run the Server program first. **
2. Open Separate second terminal window and run a client program. Please make sure the
server is up before running client code.
3. If you want to run multiple clients, open multiple terminal windows and run your client
program on One client per terminal basis.

Problem Statement
All four parts need to be submitted in the final uploaded document. Once done with lab
assignment, start with home assignment. Students can use any programming language out of
Python, Java or C. But once selected all 4 parts need to be implemented in same language.
Lab Assignment (To be Completed in College lab hours)
Part-1: Implement the following rudimentary string processing application using
connection-oriented client-server programming. Some guidelines for the implementation are as
follows. The client will send a textual paragraph terminated by ‘\n’ to the server (assume that in
the paragraph, ‘.’ appears only at the end of sentences and nowhere else). The server will
compute the number of characters, number of words, and number of sentences in the paragraph,
and send these numbers back to the client. The client will print these numbers on the screen.

Part-2: Make it concurrent so that it can serve multiple clients at a time. (Multiple clients on
multiple terminals and single server terminals)

Home Assignment (Can be completed till the submission due date)


Part-3: Write client-server application for chat server. The two clients connected to the same
server should be able to communicate with each other. Communication should be interactive and
go on till one of them terminates.

Part-4: Upgrade the code in part-3 chat server to act as both group and direct chats.

References:
Computer Networking: Top-Down Approach, by Kurose and Ross, Page 159: UDP Sockets and
Page 164: TCP Socket
Python: Socket Programming in Python (Guide) – Real Python
Java Programming: Java Socket Programming (Java Networking Tutorial) - javatpoint
C Programming: Socket Programming in C/C++ - GeeksforGeeks

P.T.O.

Common questions

Powered by AI

To upgrade a chat server application for both group and direct chats, one could implement user identification and message tagging to designate recipients. For direct chats, messages are tagged with specific recipient identifiers, ensuring they are only delivered to the intended user . For group chats, a distribution mechanism must be developed where messages are broadcast to all users in a specified group. The server should manage these configurations, maintaining lists or databases of group members and routing messages appropriately. Additionally, implementing user commands or interfaces to switch chat modes can facilitate seamless interaction .

Implementing the same programming language for all parts of an assignment ensures consistency, reduces complexity, and avoids potential integration issues. It provides uniform environments for testing and debugging, which is crucial in socket programming where different languages may have distinct nuances or library support for networking functions. A singular language approach also streamlines the learning and development process, allowing students to deepen their knowledge and proficiency with a specific socket API and language features .

A Unix-based system is advantageous for network socket programming due to its robust support for networking protocols and efficient process management features inherent in its architecture. Unix provides a stable environment with powerful command-line tools and utilities that facilitate easy scripting and automation, essential for testing and development. Its native support for multi-threading and concurrency models, along with widely available programming tools like compilers and interpreters for languages such as Python, Java, and C, makes it ideal for learning and implementing socket-based applications .

References like 'Computer Networking' and specific programming guides provide foundational knowledge and practical examples crucial for understanding the complexities of socket programming. Their detailed explanations of networking concepts such as TCP and UDP protocols, combined with code snippets and tutorials for languages like Python, Java, and C, enable students to grasp both theoretical and practical aspects of socket creation, management, and data exchange . These resources bridge knowledge gaps, offering insights into best practices and common pitfalls in socket programming, thereby enhancing comprehension and application skills in the experimental context .

When implementing a rudimentary string processing application using sockets, it is important to ensure proper data formatting and termination, such as using '\n' to indicate the end of a paragraph. The server needs to accurately parse the text to count characters, words, and sentences, using tokens like spaces and periods for separation . Systems must handle concurrency if serving multiple clients, necessitating careful management of shared resources to prevent data corruption or race conditions . Error handling mechanisms should also be incorporated to manage potential disconnections or invalid data inputs smoothly .

In socket programming, an IP address identifies the host device on a network, while a port number specifies a particular process or service on that device. Together, they form a socket address that serves as an endpoint for network communication . The IP address allows data to be routed to the correct machine, and the port number ensures that it reaches the right application or service, enabling effective process-to-process communication across networks .

The client-server paradigm aids process-to-process communication by designating specific roles to the participating processes. In socket programming, the server process listens on a specific port number and IP address, acting as an endpoint for the communication . The client process then connects to the server’s socket using its address, allowing data to be exchanged between processes on potentially different machines. This architecture ensures that multiple clients can connect to a single server endpoint, facilitating organized and scalable communication channels .

Running the server program before the client is crucial because the server must be ready to accept incoming connections when the client initiates a request. If the client runs before the server, there will be no endpoint available to establish a connection, leading to connection errors. Ensuring the server is active guarantees a listening state for incoming client requests, establishing a stable communication channel .

A basic server running a socket program handles one client at a time, processing each connection sequentially. In contrast, a concurrent server can handle multiple clients simultaneously by creating separate threads or processes for each client connection . This is achieved by implementing concurrency mechanisms such as multi-threading or asynchronous I/O, allowing the server to manage multiple concurrent connections, increasing efficiency and reducing wait time for clients .

The physical setup of multiple terminals is critical in testing concurrent socket programs as it simulates real-world scenarios where multiple clients connect to a server. Using separate terminals to run client programs ensures isolation of client processes, accurately testing the server's ability to manage multiple connections simultaneously without interference or shared state issues. This setup allows developers to observe how the server handles different connection attempts, processes requests concurrently, and returns accurate responses to each terminal independently, thereby revealing potential concurrency flaws or synchronization issues in the server implementation .

You might also like