Inspiration

I wanted to solve the issue of not being able to share files quickly b/w devices with different operating systems.

What it does

Share files and messages b/w devices.

How we built it

We built JConnect using Java and the Swing framework for the user interface. The core networking logic relies on pure Java Sockets. We implemented a peer-to-peer architecture where every client acts as both a server and a client.

Discovery: We used UDP broadcasting to allow devices to automatically find each other on the local network without a central server.

Communication: We designed a custom binary TCP protocol to handle message types, ensuring text and binary file data could be transmitted reliably over a single connection.

Concurrency: We used Java's threading primitives and SwingUtilities to ensure heavy network operations never froze the user interface.

Challenges we ran into

  • TCP Stream Fragmentation: We initially faced issues where multiple messages would arrive as a single chunk of data. We solved this by implementing a length-prefixed protocol where every packet starts with a command byte and size header.

  • UI Responsiveness: The application interface would freeze during large file transfers. We resolved this by offloading all network I/O to background threads and using the Event Dispatch Thread only for UI updates.

  • Connection Stability: Half-open connections were causing the app to think a device was online when it wasn't. We fixed this by implementing a heartbeat mechanism that sends a pulse every 2 seconds and times out inactive peers.

What we learned

  • Low-Level Networking: We gained a deep understanding of how TCP windows, buffers, and streams work at the byte level.

  • Thread Safety: We learned how to manage shared resources like socket streams using synchronization blocks to prevent race conditions during simultaneous reading and writing.

  • Swing Layouts: We learned about standard Java Swing layouts.

Accomplishments we are proud of

  • Custom Protocol Design: Instead of using HTTP or FTP libraries, we successfully wrote a raw socket protocol from scratch that handles handshakes, heartbeats, and data transfer.

  • Robust File Transfer: We built a file receiver that streams data directly to the disk using a buffer, allowing the transfer of files larger than the available RAM without crashing.

  • Zero-Config Discovery: The app requires no setup; users just open it and instantly see other devices on the WiFi.

What's next for JConnect

  • End-to-End Encryption: We plan to implement TLS or AES encryption to secure file transfers on public networks.

  • Folder Sharing: Adding the ability to zip folders on the fly so users can transfer entire directories. Resume Capability: Updating the protocol to support resuming interrupted file transfers from the last received byte.

Built With

Share this project:

Updates