| CIT
597 Assignment
4: Simple file server and client Fall 2005, David Matuszek |
Write a server program which, when requested for a file, sends that file.
Write a client program that can request files and save them.
Write a server to send files upon request, and a client to request them. Both programs will be Java applications (no HTML or JavaScript involved here).
For a simple example of a client and a server, see ReverseClient.java and ReverseServer.java. The server simply gets a text string from the client, reverses it, and sends it back. These examples are from Advanced Internet Applications with Java (2nd edition) by Art Gittleman.
ReverseClientexpects an IP address as its single parameter tomain; the parameter may belocalhostto say "this computer".
The server will start listening on a specific port (use port 8122).
The client will initiate communications on that same port. For communication to occur, the server must start up before the client.
The GUI should have (at least) these elements:
X, and the requested file
is foo/bar.html, then the server will look for it in X/foo/bar.html.javax.swing.JEditorPane to display the received file
(or error messages, if necessary). Depending on the file received, display
it as plain text, HTML, or RTF. You can find out how to do this by Sun's online
tutorial,
which is also referenced from the API.JFileChooser
dialog, so that you can save the file.You can use other GUI elements as you choose, so long as your interface is simple and obvious.
The program should not quit after downloading a single file. You can have a Quit button if you like, or you can quit the program by simply closing the window.
You do not need to write a multithreaded server.
If you have only used the AWT, not Swing, I have a program and some examples
that should greatly ease the transition for you. Download SwingExamples.zip
and unzip it in a directory of your choice. This will unzip into two files,
SwingExamples.jar and SwingExamples.java. You must
keep these files together in the same directory. Run the program by double-clicking
on SwingExamples.jar.
As described, this very simple file server has no security features whatsoever. When it is running, anyone can download any file from your computer.
Don't think that the use of an unusual port number provides any safety. It can be easily found by a port scanner.
For some very limited security, the client should send some kind of password, which the server can check, and ignore any request that does not contain this password. The password can be hard-wired into both programs; the user does not need to know that it is there.
However, for maximum security, avoid running your server while connected to the internet.