This is a simple Java application consisting of two separate programs for transferring files over a local network. The application uses Java Swing for the user interface and Java's built-in socket programming capabilities for network communication.
The sender application allows a user to select a file from their computer and send it to a receiver.
Key features:
- Simple GUI with a "Select File and Send" button
- File selection using Java's JFileChooser
- Acts as a server, waiting for a receiver to connect on port 1234
- Transfers file data in 4KB chunks for efficient memory usage
The receiver application connects to the sender and saves the received file to a specified location.
Key features:
- Simple GUI with a "Receive File" button
- Connects to localhost on port 1234
- Automatically creates the destination directory if it doesn't exist
- Saves received files to the configured destination path
-
Setup:
- Launch both applications (FileSender1 and FileReceiver1) on the same machine
- The sender acts as a server, the receiver acts as a client
-
Sending process:
- User clicks "Select File and Send" on the sender application
- User selects a file using the file chooser dialog
- The application creates a ServerSocket on port 1234 and waits for a connection
-
Receiving process:
- User clicks "Receive File" on the receiver application
- The receiver establishes a connection to localhost:1234
- Once connected, the sender reads the selected file and sends it over the socket
- The receiver reads the incoming data and writes it to the specified location
- Both applications display a success message upon completion
For the file transfer to work across multiple devices, ensure that all devices are connected to the same network. Additionally, they should share the same router-assigned IP Address. To check your IP settings:
- Open Command Prompt on Windows and run:
ipconfig
- Look for the IPv4 Address under your active network connection (e.g.,
192.168.1.15). - Use the Default Gateway (e.g.,
192.168.1.1) as the router’s IP to ensure all devices are within the same network.
For Linux/macOS, use the following command in Terminal:
ip aEnsure all devices share the same subnet (e.g., 192.168.1.xxx) to allow smooth communication.
Important: This application does not work on mobile hotspots. You need a router or a local network for proper functionality.
- Network protocol: TCP/IP (using Java Sockets)
- Buffer size: 4096 bytes
- Port: Fixed to 1234
- Connection type: Localhost (127.0.0.1)
- Default configuration needed: You must configure the destination directory path before using the receiver application.
- Fixed file name: The receiver saves the file with a fixed name regardless of the original file type or name.
- Connection handling: The applications don't handle connection timeouts or retry mechanisms.
- Single-threaded: Both applications block during file transfer operations.
- No progress indication: Users don't see transfer progress during operation.
- Sequential operation: The sender must be ready before the receiver initiates the connection.
Before using the FileReceiver1 application, you need to set your desired destination directory:
- Open the FileReceiver1.java file in a text editor.
- Locate the
receiveFile()method. - Change the
directoryPathvariable to your preferred directory:String directoryPath = "YOUR_DESIRED_PATH_HERE";
- Optionally modify the file name from "received_file.png" to something more appropriate for your use case:
String savePath = directoryPath + "\\YOUR_DESIRED_FILENAME";
- Add dynamic file naming based on the original file name.
- Implement a configurable destination directory via user interface.
- Add progress bars to show transfer status.
- Implement error handling and retry mechanisms.
- Support for transferring multiple files.
- Enable transfers across different machines (not just localhost).
- Add encryption for secure file transfers.
- Implement file integrity verification.