Skip to content

Ivanlaguna511/Distributed-Spotify-TCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 

Repository files navigation

SDIS Module 2: Distributed Spotify TCP Server

Java Sockets Serialization Concurrency Academic

ABOUT THIS MODULE: This repository contains Module 2 of the Distributed Systems (SDIS) course project. It elevates the architecture from Module 1 by implementing a complex, multithreaded server simulating a Spotify-like playlist manager. Instead of raw text, this module utilizes Java Object Serialization to transmit immutable ProtocolMessage structures safely across the network.


Architecture & Key Features

Building upon the anti-brute force mechanisms of Module 1, this module introduces advanced thread-safe state management:

  • Custom Binary Protocol: Network communication is strictly typed using a custom ProtocolMessage DTO and a ProtocolPrimitive Enum, ensuring predictable parsing.
  • Stateful Sessions: The server maintains an isAuthenticated state per client handler, rejecting protected commands (ADD2L, DELETEL) via HTTP-like 401 and 403 logical errors if not logged in.
  • Thread-Safe Generic ConcurrentMultiMap: * Implements a non-blocking map ConcurrentMap<K, ConcurrentLinkedQueue<T>>.
    • Allows hundreds of concurrent clients to add (push) and read (pop) songs from playlists atomically without locking the entire map.
  • Deadlock Prevention: Safe initialization of ObjectOutputStream using flush() before ObjectInputStream instantiation, avoiding the classic Java Sockets blocking deadlock.

Project Structure

src/sdis/spotify/
 ┣ 📂 common
 ┃ ┣ 📜 ProtocolPrimitive.java     # Protocol Commands (XAUTH, ADD2L...)
 ┃ ┣ 📜 ProtocolMessage.java       # Immutable Serializable DTO
 ┃ ┗ 📜 ServerMessages.java        # Centralized string constants
 ┣ 📂 utils
 ┃ ┣ 📜 ConnectionManager.java     # Rate-limiting and Brute-Force protection
 ┃ ┗ 📜 ConcurrentMultiMap.java    # Thread-Safe generic Queue mapping
 ┣ 📂 server
 ┃ ┣ 📜 SpotifyServer.java         # Thread Pool (ExecutorService) init
 ┃ ┗ 📜 ClientHandler.java         # Runnable protocol executor
 ┗ 📂 client
   ┗ 📜 SpotifyInteractiveClient.java  # CLI Client for interactive testing

Getting Started

1. Compilation

Navigate to the root directory and compile the entire project structure:

javac sdis/spotify/common/*.java sdis/spotify/utils/*.java sdis/spotify/server/*.java sdis/spotify/client/*.java

2. Execution

Start the Server:

java sdis.spotify.server.SpotifyServer

Start the Interactive Client:

java sdis.spotify.client.SpotifyInteractiveClient

Interaction Example Client Terminal (Adding a song):

--- SPOTIFY MENU ---
1. Login
2. Add Song to Playlist
3. Read Playlist
4. Delete Playlist
Select an option: 2
Playlist Name: Rock Classics
Song Name: Stairway to Heaven
>> Sending: ADD2L: Rock Classics -> Stairway to Heaven
<< Received: ADDED

Server Logs:

SERVER: [STARTING] on Port 2000
SERVER: New connection from 127.0.0.1
Handler [0]: Processed ADD2L from 127.0.0.1 successfully.

Authors

-Iván Moro Cienfuegos, David Martín Sebastián, Eric Soto San José and Héctor

About

Multithreaded TCP Client-Server architecture simulating a Spotify-like playlist management system. Built with custom object serialization, thread-safe structures, and IP rate-limiting.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages