Create your own Simple File Transfer App over LAN (with Source code in JAVA)

Many Core Java packages can be used to create useful applications. This application uses package to establish connection between two systems residing on the same network.  This point is important, because it will not work for arbitrary networks (having no connection between them). For those who don’t have basic networking knowledge, in the simplest language same network means computer systems connected through the same router, or directly connected to each other via LAN Wire.

Networking Basics : When we connect to a network (a router), we get an IP from the router, which is usually of the form, where x is a no. between 0 to 255 like or . Usually the first address in the series is of the router itself, i.e.
In networking, there is a simple concept of a socket which is the combination of IP Address and Port number. Port no. is a is a no. between 0 to 65535. Out of this, 0 to 1023 are reserved for specific services and 1024 to 65536 can be used for our codes. In java, there are two classes which help in communication via these ports. These are namely, and  Socket acts as a client and ServerSocket acts as a server.

This simple software uses these two classes to send and receive files. ServerSocket opens a port on a system and waits for a client to connect to that port. On the other end, a system on the same network uses Socket class to connect to this device to establish connection and recieve data. The serveris currently able to send one file at a time to client.

The image shown below shows both the Client and Server side applications :


The Server Side Application has options to select the file to be sent and then press the button “Send File”. For the client side, it has a text field where we enter the address specified by the server (which is here). The default location where the client saves the file is Desktop of the user but the user can change the path where these files are saved after downloading. But, protected paths like C: and C:Program Files should be avoided as the destination paths, else an error is shown and Client shutdowns. The default location is then reset again to Desktop.

A simple setup using Batch script, VB Script,Registry Script and Winrar was created to deploy the JAR file onto Windows Systems both 32 and 64 bit. JRE/ JDK 1.4 or above should be installed to use this application. You can try this application on your same system (local server) by using as server address on client side.After installation on windows system, you will get these options on Right Click of each file/folder (called as context menu), which allows instant sharing as shown below.

Screenshot of Installed Program

Screenshot of Installed Program

Download the application from here


Client side source code ( :

Server Side code (

Just let us know if you are not able to understand any method or class used here


  1. what does lastIndexOf(“/”) returns? I mean we do not have a backslash in ip addresses?

  2. @simran : please specify line no. and the code you are talking about (client/server)

    If you are having problem in getLocalHost() method then here is the reason :InetAddress.getLocalHost() returns IP with the PC name like : Waheguru_HP/

    to display only IP and remove PC name, I have used lastIndexOf(“/”);

  3. lastIndexOf(“/”) return the position of the character that occurs rightmost from beginning of the string.

    String s = “The Geeky way”;
    This will return: 6.

    Notice that char “e” is trice in the given string. It searches and finds the last occurring position of char “e”.
    Spaces are also included as character and index always start from 0.

    Program given in post : “/” is being used to separate computer name (Host name) and IP.

Leave a Reply

Your email address will not be published. Required fields are marked *