hi all, I have created a servergui class, a server class (funtionalities), and a clientgui class.
As i am using GUI, i did not allow the user to define the directory for the server to serve files.
(clientgui) I have a simple portno. field and ip field allowing clients to connect to the server. I have already taken care of clicking 'connect' with empty inputs by appending to the console the usage message. However, it (the message) doesnt appear.
(server) The server can append " listening for connections " at first, but when a client is connected to it, the message that i append to tell the one at the server that a client has connected to the server does not append as well.
To the more important part, sending and receiving, either messages written by the server to the client ,OR , client sending the filename to the server after typing down the filename and clicking 'download',OR , server sending files to client, doesnt seems to work.
public void sendFile(String filename) throws Exception
file = new File(filename);
if ((! file.exists()) || file.isDirectory())
pw.println("File error,Pls enter a valid file\n");
pw.println("Success! Reading " + filename + "...\n");
pw.println("Sending file to " + socket.getInetAddress().getHostName() + " now.\n");
// read lines from file and send to the client
BufferedReader input = new BufferedReader(new FileReader (file));
while ((line = input.readLine()) != null)
throw new Exception("Error while transmitting data.");
public void run()
pw.println("client running now.\n");
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
pw = new PrintWriter(socket.getOutputStream() );
String filename = br.readLine();
catch (Exception e)
catch (IOException e)
my questions are:
1) i use printwriters to write from servers to clients and clients to servers, some msg like to tell the clients they have successfully found the file and ready to receive the file is not appended to the console of the client. how can i correct that?
2) becos client only states the filename, does tat mean the boundary of the files found is the folder which holds these java files?
3) and if so? how isit going to write to the same folder? with the same name?
4) and when i receive input streams for eg from server to client, how can i differentiate whether it a line from the file or it is actually the server msgs? (Note: i did not use File'Input/Output'Streams) Should i use? and how can i append the server msgs to the console of clientgui?
Whats happening to my codes now:
1) the 3 files are compilable.
2) when i connected successfully, no appended server msgs to server console to inform user of connected client.
3) when i try to put in invalid port and ip, no appended error msgs. (however the command prompt will have a list of errors listing out)
4) when i connected properly to the server and typed in test.txt which i have created in the same directory as the java files and then click jbutton donwload, im not sure whether is there sending of the file over to client and im not sure where will it reside. Lastly, after clicking download with a valid txt file, the clientgui just hang there, which i have to ctrl+alt+del to terminate it. What should i do?
I hope can get help from here... since all my frens are also stuck with their own assignment as well..
thanks alot. (hmm, im left with 25 points........ =( .......... )