Skip to content

aparreno14/java-concurrent-p2p-images

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Concurrent P2P Image Sharing (Java)

Coursework project for Concurrent Programming (UCM), 2024–2025. A client–server directory plus peer-to-peer (P2P) image transfer system built with Java, TCP sockets, and a Swing GUI.

Authors

  • Alejandro Parreño Minaya — @aparreno14
  • Diego Ostos Arellano

What this project does

  • Clients connect to a central server to register and publish a list of available images.
  • When a client requests an image, the server matches requester ↔ owner.
  • The actual file is transferred directly between clients (P2P) over TCP.

Architecture (high level)

Server (directory / broker)

  • Listens on a fixed TCP port (see src/server/Server.java).

  • Maintains:

    • active users and their published image lists
    • input/output streams per user
  • Spawns dedicated listener threads to handle multiple clients concurrently.

  • Provides a Swing GUI to display connected users and server logs.

Client

  • Swing GUI client.

  • Talks to the server for:

    • registration
    • listing available images
    • requesting an image
  • For P2P transfers:

    • Emitter opens a temporary TCP port and serves the requested file to the peer.
    • Receiver connects to that temporary port and downloads the image.

Message protocol (overview)

The system uses a custom message protocol (serializable objects) with message kinds such as:

  • CONEXION / CONF_CONEXION
  • LISTA_PRODUCTOS / CONF_LISTA_PRODUCTOS
  • PEDIR
  • EMITIR
  • PREPARADO_CS → server (emitter announces P2P port)
  • PREPARADO_SC → requester (server forwards P2P port)
  • IMAGEN_NO_EXISTE
  • CERRAR_CONEXION / CONF_CERRAR_CONEXION

Data folders (important)

This project expects local folders under data/:

  • Images you want to share should be placed under: data/<userId>/
  • Downloaded images are saved under: data/<userId>/descargas/

Tip: create those folders for each user you test with.

How to run (Eclipse recommended)

This project was developed with Windows + Eclipse.

  1. Import the project in Eclipse (existing project from filesystem).

  2. Run the server:

    • Run src/server/Launcher.java (starts the GUI + server loop).
  3. Run two clients (in separate runs):

    • Run src/cliente/Cliente.java twice.
  4. Use the GUI to:

    • connect/register with different userIds
    • publish images (by placing files in data/<userId>/)
    • request an image from the global list and download it via P2P

Notes:

  • Local testing assumes localhost.
  • Make sure your firewall allows local TCP connections (server port + temporary P2P ports).

Repository structure

  • src/server/ — server logic + GUI
  • src/cliente/ — client GUI + P2P emitter/receiver threads
  • src/mensajes/ — message classes and enums
  • src/tablas/ — shared tables (users/streams/products) with concurrency control
  • src/semaforos/, src/locks/ — synchronization primitives used by the tables

License

GPL — see LICENSE.

Disclaimer

This is an educational project developed for a university course.

About

Concurrent Java client–server + P2P image sharing (Swing UI, TCP sockets, custom message protocol).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages