Suttree.com: Casual Games, Social Software

Read more at the weblog »

Java client/server sockets application

Having worked extensively on a website for a client, it became clear that they were not using as much as we all had hoped. After a few meetings it became clear that this was due to the fact that they were not comfortable using traditional web forms to update their site. This made a lot of sense, as their primary requirement was to provide an up-to-date online presence without getting tied down by computers and the internet, etc. We agreed that they would be much happier using a traditional desktop application to update their website, which led me to code this simple application.

Now they can just launch the application, use a traditional explorer style file browser to select the file they want to use to update the webiste, and hit the 'send' button. The application contains a client that opens a socket on their machine, connects to the server and transfer the file across. Since this file is in a format that we have previosuly agreed upon, a .csv file for example, then once the server has received it, it can be parsed and imported into the database - therefore updating the website, without having to go anywhere near it. So far it has been a great success.

Usage
Once you have made a few configuration changes to the code, and compiled it, the application should be very simple to operate. Run the client class on a remote machine, browse for a file and hit send. Provided that the server is running on your host machine, then the file will be transferred across. The server is set to run forever, so once you start it, you should be able to forget about it entirely.

Installation
First, decompress the two tar.gz files, and the make the following configuration changes.
In the Server folder, look for a file called Server.java, and modify the following two lines to whatever you prefer;

static final String OUTPUTFILENAME = "C:\receivedData";
static final int PORT = 5791;


So, for instace, you can change PORT to a different number, as that is the port which the server will listen on, and configure your firewall accordingly.
Also, the files received by Server.java will be copied to a file specified by OUTPUTFILENAME, so you can change the name and location of that file by modifying this line.
In the Client folder, look for a file called Client_socket.java, and modify the following lines;

static final int PORT = 5791;
static final String HOST = "127.0.0.1";


Change PORT to match the PORT variable in Server.java, and change HOST so that it contains the IP address of the machine that will be running Server.java.
Once that's done, you can compile both Client and Server and test them out.

Download
Java client/server sockets application can be downloaded from here;
Download Client
Download Server

Version 2
Version 2 is underway planned (including more error checking, and some XML-RPC calls to finish the job), but flames, feedback and questions can be directed to me, .

Suttree Beatniks with better clothing, brought to you by Duncan Gough. About Archives Casual Game Dev Code Disclaimer EcoLocal Music Knows PMOG Tumblee
Links for Saturday, October 11th, 2008