Lab 1: Socket Programming - Foundation for Distributed Systems
Preamble: The Journey to Enterprise Java
Welcome to CSD-4464! This course charts an exciting journey through the evolution of distributed systems, starting with the foundational building blocks and progressing to enterprise-grade architectures.
Think of it as climbing a mountain of abstraction - each layer building upon the previous one to create increasingly powerful and flexible systems.
The Knowledge Lineage
In this course, we'll traverse five crucial layers of distributed computing:
1. **Sockets** (Where we are now) - The fundamental communication channel between networked processes
2. **Remote Method Invocation (RMI)** - Object-oriented abstraction over network communication
3. **JSP/JSF with Servlets** - Web-centric presentation and processing
4. **Enterprise JavaBeans (EJB)** - Component-based business logic and transaction management
5. **JAX Web Services** - Platform-independent service-oriented architecture
Once we get here, we will fold on JPA Java Persistance Architecture by connecting to a MySQL database and build a complete MVC application.
We begin with sockets because they represent the raw essence of network communication - the ability for two processes to exchange information across a network. Understanding sockets provides crucial insights into how all higher-level abstractions ultimately work.
Why This Progression Matters
Modern enterprise applications are built using JAX-RS (REST) or JAX-WS (SOAP) web services, but these sophisticated frameworks abstract away the underlying network communication.
By starting with sockets, you'll gain a deep understanding of:
- How distributed systems fundamentally communicate
- The challenges of network programming (latency, failures, concurrency)
- Why higher-level abstractions are valuable
- The trade-offs between simplicity and power at each layer
### Our Development Environment
We'll use a minimalist but powerful toolkit:
- MySQL for persistence
- GlassFish as our Java EE application server
- Sublime Text as our editor
We've chosen Sublime Text over more complex IDEs to maintain focus on the core concepts rather than IDE-specific workflows. This approach ensures you understand the fundamental principles without the overhead of learning complex tool chains.
## Lab 1 Instructions
### Objective
Create a multi-client chat application using Java sockets, demonstrating fundamental network programming concepts and laying the groundwork for understanding distributed systems.
### Requirements
1. **Server Implementation (40 points)**
- Create a server that accepts multiple client connections
- Implement thread management for concurrent client handling
- Maintain a list of connected clients
- Properly handle client disconnections
2. **Client Implementation (30 points)**
- Implement connection to server
- Handle user input and server messages concurrently
- Provide clean shutdown mechanism
- Display appropriate status messages
3. **Protocol Implementation (20 points)**
- Define clear message format for client-server communication
- Implement user identification mechanism
- Handle broadcast messages
- Manage connection/disconnection messages
4. **Code Quality (10 points)**
- Clear documentation and comments
- Proper exception handling
- Clean code organization
- Following Java naming conventions
### Deliverables
1. **Source Code**
- Server.java
- Client.java
- Any additional utility classes
- README.md explaining how to run your application
2. **Documentation**
- Brief design document explaining your implementation choices
- Protocol specification
- Known limitations or issues
3. **Test Results**
- Screenshots showing multiple clients connected
- Evidence of proper message broadcasting
- Demonstration of graceful error handling
### Submission Guidelines
1. Create a ZIP file containing all deliverables
2. Name the file: `Lab1_StudentID_LastName.zip`
3. Submit through the designated course submission system
4. Ensure all code is properly commented and formatted
## Grading Rubric
### Server Implementation (40 points)
- Multi-client support (15 points)
- Excellent: Handles multiple clients flawlessly with proper thread management
- Good: Handles multiple clients with minor issues
- Fair: Basic multi-client support with significant limitations
- Poor: Single client only or major issues
- Connection Management (15 points)
- Excellent: Robust handling of connections/disconnections
- Good: Proper connection management with minor issues
- Fair: Basic connection management with some bugs
- Poor: Unreliable connection management
- Error Handling (10 points)
- Excellent: Comprehensive error handling and recovery
- Good: Most error cases handled appropriately
- Fair: Basic error handling
- Poor: Minimal or no error handling
### Client Implementation (30 points)
- User Interface (10 points)
- Excellent: Clear, intuitive interface with status updates
- Good: Functional interface with basic status information
- Fair: Basic interface with minimal feedback
- Poor: Confusing or broken interface
- Message Handling (10 points)
- Excellent: Smooth message sending/receiving with proper threading
- Good: Reliable message handling with minor issues
- Fair: Basic message handling with some bugs
- Poor: Unreliable message handling
- Resource Management (10 points)
- Excellent: Proper cleanup of resources, graceful shutdown
- Good: Most resources properly managed
- Fair: Basic resource management
- Poor: Resource leaks or improper cleanup
### Protocol Implementation (20 points)
- Message Format (10 points)
- Excellent: Well-defined, efficient protocol
- Good: Clear protocol with minor inconsistencies
- Fair: Basic protocol with some issues
- Poor: Poorly defined or inconsistent protocol
- Feature Support (10 points)
- Excellent: All required features implemented properly
- Good: Most features implemented with minor issues
- Fair: Basic feature implementation
- Poor: Missing key features
### Code Quality (10 points)
- Documentation (4 points)
- Excellent: Comprehensive, clear documentation
- Good: Adequate documentation with minor gaps
- Fair: Basic documentation
- Poor: Minimal or unclear documentation
- Code Organization (3 points)
- Excellent: Well-organized, modular code
- Good: Mostly organized code with some issues
- Fair: Basic organization
- Poor: Poor organization or structure
- Coding Standards (3 points)
- Excellent: Follows all Java conventions
- Good: Mostly follows conventions
- Fair: Some adherence to conventions
- Poor: Ignores conventions
## Mapping to Course Learning Outcomes
This lab specifically addresses the following course learning outcomes:
1. CLO 1.1: Configure and use testing frameworks
- Implementation of basic testing for network communication
2. CLO 1.4: Implement source-control techniques
- Organization and submission of code demonstrates version control practices
3. CLO 2.6: Utilize functional programming paradigm
- Use of lambda expressions for thread handling
4. CLO 3.3: Manage network requests
- Direct implementation of socket-based communication
5. CLO 3.9: Implement contexts and dependency injection
- Basic introduction through socket connection management
Remember: This lab sets the foundation for understanding how distributed systems communicate at their most basic level. The skills you develop here will be crucial as we progress to more sophisticated architectures in subsequent labs.