Hi guys!

I have made a multithreaded Server and client program in which the client connects, has a little discussion, is presented with a list of options for file download and is then meant to download the selected file.

My problem is that the discussion happens fine and the options are presented but after the server sends "Sending File" no file is received at the client end.

My client is below:
import java.io.*;
import java.net.*;

Code:
public class Client {
    //define states
    private static final int WAITTEXT = 1;
    private static final int WAITFILE = 2;
    //and our current state
    private static int state = WAITTEXT;
    
    public static void main(String[] args) throws IOException {
 
        Socket ourSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
 
        //try and connect
        try {
            ourSocket = new Socket("127.0.0.1", 2222);
            out = new PrintWriter(ourSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(ourSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Can't find host: 127.0.0.1");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to 127.0.0.1");
            System.exit(1);
        }
 
        //set up
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String fromServer;
        String fromUser;
        OUTER:
        while ((fromServer = in.readLine()) != null) {
            //if we are waiting for text do the below
            if(state == WAITTEXT){
                System.out.println("Server: " + fromServer);
                switch (fromServer) {
                    case "Connection Closed":
                        break OUTER;
                    case "Sending File":
                        state = WAITFILE;
                        break;
                }
                if(state == WAITTEXT){
                    fromUser = stdIn.readLine();
                    if (fromUser != null) {
                        System.out.println("Client: " + fromUser);
                        out.println(fromUser);
                    }
                }
            }//else if we are waiting for a file
            else if(state == WAITFILE){
                int bytesRead;
                int current = 0;
                byte [] mybytearray = new byte [6022386];
                InputStream is = ourSocket.getInputStream();
                FileOutputStream fos = new FileOutputStream("name.file");
                BufferedOutputStream bos;
                bos = new BufferedOutputStream(fos);
                bytesRead = is.read(mybytearray,0,mybytearray.length);
                current = bytesRead;
                do {
                    bytesRead = is.read(mybytearray,current,(mybytearray.length-current));
                    if(bytesRead >= 0) {
                        current += bytesRead;
                    }
                } while (bytesRead > -1);
                bos.write(mybytearray,0,current);
                bos.flush();
                bos.close();
                System.out.println("Client: Received");
                state = WAITTEXT;
            }
        }
 
        //close everything
        out.close();
        in.close();
        stdIn.close();
        ourSocket.close();
    }
}
I have posted the server thread code http://pastebin.com/JtHcB9SC
I don't think it is anything to do with the server side, but as far as I can see with the use of states on the client side everything should be fine!

Any help or pointers at all would be appreciated!