Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Tolls

Thread: how to increase the file size to be upload or download between client and server

  1. #1
    awpad is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default how to increase the file size to be upload or download between client and server

    Hi everybody , I'd like u to help me to increase the file size that will upload or download between client and server " now i can send or receive 70 mb but once i want to increase the size to for instance 300 or 400 MB it doesn't accept
    Here is part of the code
    Server code :
    Java Code:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    
    public class ServerGUI extends javax.swing.JFrame {
    
        public String path;                         //serverFile path
        public String str = "";                     //file shares list
        public String remoteClientAddress = "";
        public ServerSocket servSocket = null;      //tcp socket for server
        public Socket sock = null;                  //server socket for connection management
        public int servPort = 0;                        //server Port number
        public DataOutputStream fileDir = null;     //to sent shares file name
        public DataInputStream selectedFile = null; //to accept client selected file name
        public DataInputStream command = null;      //to sent or receive file
        public int clientConnectStatus = 0;         //0 = client connect for the first time
        public int fileShareList = 0;               //0 = sending file share list for the first time
        public Thread readThread;                   //mainThread to handle connection for server
        public File Filelist [];
    
        /** Creates new form ServerGUI */
        public ServerGUI() {
            initComponents();
        }
    
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jLabel4 = new javax.swing.JLabel();
            jScrollPane2 = new javax.swing.JScrollPane();
            DirectoryInfo = new javax.swing.JTextArea();
            jLabel5 = new javax.swing.JLabel();
            jLabel1 = new javax.swing.JLabel();
            StartServer = new javax.swing.JButton();
            StopServer = new javax.swing.JButton();
            jLabel2 = new javax.swing.JLabel();
            PortSelected = new javax.swing.JTextField();
            PortSelection = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            ActivityLog = new javax.swing.JTextArea();
            SetPath = new javax.swing.JButton();
            TF_FilePath = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Server interface ");
            setBackground(new java.awt.Color(0, 255, 255));
            setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
            setForeground(java.awt.Color.white);
            setResizable(false);
    
            jLabel4.setText("* Port Number must be between(1024-65534)");
    
            DirectoryInfo.setColumns(20);
            DirectoryInfo.setEditable(false);
            DirectoryInfo.setForeground(new java.awt.Color(0, 0, 255));
            DirectoryInfo.setRows(5);
            jScrollPane2.setViewportView(DirectoryInfo);
    
            jLabel5.setText("Active Log :");
    
            jLabel1.setText("List of Shared Files:");
    
            StartServer.setActionCommand("Start ");
            StartServer.setFocusCycleRoot(true);
            StartServer.setFocusTraversalPolicyProvider(true);
            StartServer.setLabel("Start ");
            StartServer.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    StartServerActionPerformed(evt);
                }
            });
    
            StopServer.setActionCommand("End ");
            StopServer.setEnabled(false);
            StopServer.setLabel("End ");
            StopServer.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    StopServerActionPerformed(evt);
                }
            });
    
            jLabel2.setText("Port Number:");
    
            PortSelected.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    PortSelectedActionPerformed(evt);
                }
            });
    
            PortSelection.setText("Set Port Number");
            PortSelection.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    PortSelectionActionPerformed(evt);
                }
            });
    
            ActivityLog.setColumns(20);
            ActivityLog.setEditable(false);
            ActivityLog.setForeground(new java.awt.Color(0, 0, 255));
            ActivityLog.setRows(5);
            jScrollPane1.setViewportView(ActivityLog);
    
            SetPath.setText("Browse");
            SetPath.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    SetPathActionPerformed(evt);
                }
            });
    
            TF_FilePath.setEditable(false);
    
            jLabel3.setText("LocateShraing Folder :");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 694, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(PortSelected, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(PortSelection)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 242, Short.MAX_VALUE)
                            .addComponent(StartServer, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(48, 48, 48)
                            .addComponent(StopServer, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(TF_FilePath, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(SetPath)
                            .addGap(119, 119, 119))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(32, 32, 32)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(70, 70, 70))))
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE)
                            .addContainerGap())))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 379, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addGap(28, 28, 28)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(PortSelected, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(PortSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(StopServer)
                        .addComponent(StartServer))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel4)
                    .addGap(11, 11, 11)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(TF_FilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(SetPath)
                        .addComponent(jLabel3))
                    .addGap(29, 29, 29)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void StartServerActionPerformed(java.awt.event.ActionEvent evt) {                                            
    
            if(servPort==0 || TF_FilePath.getText().equals("")) {
                JOptionPane.showMessageDialog(null,"Please make sure that you entered a valid port number and a shraing folder path Before Starting a session","WARNING",0);
            } else {
                preventGUIFreezing();
                Runnable readRun = new Runnable() {
                    public void run() {
                        PortSelection.setEnabled(false);
                        SetPath.setEnabled(false);
                        StartServer.setEnabled(false);
                        StopServer.setEnabled(true);
                        ActivityLog.append("Server is Waiting for Clients to connect.\n");
                        try {
                            servSocket = new ServerSocket(servPort); //prepare socket
                        } catch(Exception e) {
                            JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                        }
                        while(true) {
                            try {
                                sock = servSocket.accept(); //listen for client to connect
                                if(clientConnectStatus==0) {
                                    remoteClientAddress = sock.getInetAddress().toString().substring(1,(sock.getInetAddress().toString().length()));
                                    ActivityLog.append("Server Connected to "+remoteClientAddress+"\n");
                                    clientConnectStatus = 1;
                                }
                            } catch(Exception e) {
                                JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                            }
                            //sent the share files name to client
                            try {
                                fileDir = new DataOutputStream(sock.getOutputStream());
                                fileDir.writeUTF(str);
                                if(fileShareList==0) {
                                    ActivityLog.append("Sent the share file list to client.\n");
                                    fileDir.flush();
                                    fileShareList = 1;
                                }
                            } catch(Exception e) {
                                JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                            }
                            FileHandle();
                        }
                    }
    
                    public void FileHandle() {
                        //receive File name selected by the client
                        String filename = "";
                        try {
                            selectedFile = new DataInputStream(sock.getInputStream());
                            filename = selectedFile.readUTF();
                        } catch(Exception e) {
                            JOptionPane.showMessageDialog(null," Client connected successfully ","NOTIFICATION",1);
                            //Server Established Connection to the Client for the first time
                            //FOR the first cycle , selectedFile will be NULL since client hasnt
                            //request for any GETFILE or PUTFILE command
                        }
                        if(filename.equals("")) {
                            JOptionPane.showMessageDialog(null,"Server is started sharing Files ","Notification",1);
                        } else {
                            //if COMMAND = GET
                            if(filename.substring(0,3).equalsIgnoreCase("get")) {
                                sentFile(filename.substring(3,filename.length()));
                            }
                            //if COMMAND = PUT
                            if(filename.substring(0,3).equalsIgnoreCase("put")) {
                                receiveFile(filename.substring(3,filename.length()));
                            }
                        }
                    }
    
                    public void receiveFile(String lop) {
                        try {
                            Socket sock2 = servSocket.accept();
                            ActivityLog.append("Start Receiving files ->"+lop+"\n");
                            int bytesRead2;
                            int current2 = 0;
                            long start = System.currentTimeMillis();
    
                            //receive file
                            DataInputStream i2 = new DataInputStream(sock2.getInputStream());
                            int filesize2 = i2.readInt(); //READING THE FILE SIZE from sender
                            byte [] mybytearray2  = new byte [filesize2];
                            InputStream is2 = sock2.getInputStream();
                            FileOutputStream fos2 = new FileOutputStream(path+"/"+lop);
                            BufferedOutputStream bos2 = new BufferedOutputStream(fos2);
                            bytesRead2 = is2.read(mybytearray2,0,mybytearray2.length);
                            filesize2 = filesize2 - bytesRead2;
                            current2 = bytesRead2;
                            do
                            {
                                bytesRead2 = is2.read(mybytearray2, current2, (mybytearray2.length-current2));
                                if(bytesRead2 >= 0) {
                                    current2 += bytesRead2;
                                }
                                filesize2 = filesize2 - bytesRead2;
                                System.out.println(current2);
                            } while(filesize2>-1);
    
                            bos2.write(mybytearray2, 0 , current2);
                            bos2.flush();
                            long end = System.currentTimeMillis();
                            ActivityLog.append("File Transfer will Complete in ->"+(end-start)+"ms.\n");
                            bos2.close();
                            sock2.close();
                        } catch(Exception e) {
                            JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                        }
                    }
                    //string l = filename selected by the client
                    public void sentFile(String l) {
                        if(l.equals("")) {
                            //DoNothing
                        } else {
                            ActivityLog.append("Client has selected file to share -> "+l+"\n");
                            ActivityLog.append("Start Sending File. \n");
                            try {
                                //1024 experiment version sending
                                File myFile = new File(path+"/"+l);
                                DataOutputStream o = new DataOutputStream(sock.getOutputStream());
                                FileInputStream fis = new FileInputStream(myFile);
                                BufferedInputStream bis = new BufferedInputStream(fis);
                                long lenth=bis.available(); //GET THE INITIAL FILE SIZE
                                o.writeInt((int)lenth); //SEND TO CLIENT TO TELL THE TOTAL FILE SIZE
                                byte bytes[] = new byte[bis.available()];
                                int writecount;
                                while (lenth > 0) {
                                    if(lenth>=1024) {
                                        writecount = 1024;
                                    } else {
                                        writecount = (int)lenth;
                                    }
                                    bis.read(bytes, 0, writecount);
                                    ActivityLog.append("Bytes Left "+lenth+"\n");
                                    o.write(bytes, 0,  writecount);
                                    lenth = lenth - writecount;
                                }
                                o.flush();
                                sock.close();
                                ActivityLog.append("File Finish Sending. \n");
                                //1024 experiment version sending
                            } catch(Exception e) {
                                JOptionPane.showMessageDialog(null,e.getMessage(),"WARNING!!",0);
                            }
                        }
                    }
                };
                readThread = new Thread(readRun);
                readThread.start();
            }//end the FIRST IF statement
    }                                           
    
        private void StopServerActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
            JOptionPane.showMessageDialog(null,"Thank you ");
            System.exit(1);
    }                                          
    
        private void PortSelectedActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
    }                                            
    
        private void PortSelectionActionPerformed(java.awt.event.ActionEvent evt) {                                              
            try {
                int tempPort = Integer.parseInt(PortSelected.getText());
                if(tempPort>1023 && tempPort<65535) //start from 1024 - 65534
                {
                    servPort = tempPort;
                    ActivityLog.append("Port number set To -> "+servPort+"\n");
                } else {
                    JOptionPane.showMessageDialog(null,"Please Enter a valid Port Number, between {1024 - 65534}","Error!!!",0);
                }
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null,"Please Enter Numbers Only, between {1024 - 65534}","Error!!!",0);
            }
    }                                             
    
        private void SetPathActionPerformed(java.awt.event.ActionEvent evt) {                                        
    
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int returnVal = chooser.showOpenDialog(this);
            if(returnVal == JFileChooser.APPROVE_OPTION)    //if the path selected is valid
            {
                path = chooser.getSelectedFile().getPath(); //set the path into a String
    
                //update The Directory List
                File path2 = new File(path);
                Filelist = path2.listFiles();  //set filelist = path selected
                for(int k=0; k<Filelist.length;k++) //fill up str array with filelist
                {
                    if(Filelist[k].isDirectory()) //if the file is directory
                    {
                        continue;
                    } else {
                        if(Filelist[k].length()<=902238600) //maximum file size 700mb
                        {
                            str = str+Filelist[k].getName()+"\n";  //str will be display in server
                        }
                    }
                }
                if(DirectoryInfo.getText().equals("")) //if directory textArea is empty
                {
                    DirectoryInfo.setText(str); //append the file list
                    ActivityLog.append("Sharing folder path set to -> "+path+"\n");
                    TF_FilePath.setText(path);
                } else {
                    DirectoryInfo.setText(""); //clear the directory textArea
                    DirectoryInfo.setText(str);
                    ActivityLog.append("Sharing folder path set to -> "+path+"\n");
                    TF_FilePath.setText(path);
                }
            }
    }                                       
    
        //STOP SERVER CODE
        //SET FILE PATH
        //START SERVER
        //SELECT PORT
        public static void main(String args[])
        {
            java.awt.EventQueue.invokeLater(new Runnable()
            {
                public void run()
                {
                    new ServerGUI().setVisible(true);
                }
            });
        }
    
        //method to make sure the threads does not lock up repainting
        public void preventGUIFreezing()
        {
             if(SwingUtilities.isEventDispatchThread())
             {
                return;
             }
             throw new RuntimeException("file");
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JTextArea ActivityLog;
        private javax.swing.JTextArea DirectoryInfo;
        private javax.swing.JTextField PortSelected;
        private javax.swing.JButton PortSelection;
        private javax.swing.JButton SetPath;
        private javax.swing.JButton StartServer;
        private javax.swing.JButton StopServer;
        private javax.swing.JTextField TF_FilePath;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        // End of variables declaration                   
    
    }
    }
    Last edited by awpad; 08-04-2011 at 04:20 AM.

  2. #2
    awpad is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Actually , there is no error at all , it works properly , but once i want to send or receive any file which is more than 70 Mb , it start to send or receive until 70 Mb and then freeze
    To terminate the session , I press end button
    so my question again is , i just want to be able to send or receive more than 70 Mb
    Appreciate all your replies

    Client Code :
    Java Code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    
    public class ClientGUI extends javax.swing.JFrame {
    
        public ServerSocket clientSocket = null; //tcp socket for client
        public Socket sock = null;               //client socket for connection management
        public DataInputStream streamIn = null;  //receive information from server
        public DataOutputStream streamOut = null;//sent information to server
        public String filelist = "";             //filelist receive from server
        public String [] filelist2;              //formated filelist to display in the JList
        public String selectFile = "";           //selected file's name to request to server
        public int serverPort = 0;                   //server port number
        public String serverAddress = "";             //server IP Address
        public Thread readThread;                //handle connection establish to server
        public Thread getFileThread;             //get file from server
        public Thread sendFileThread;            //send file to server
        public String path;                      //client share file path
        public String [] clientFileList;         //formated client share filelist to display in the JList
        public int serverStatus = 0;             //0 = connected
    
    
        /** Creates new form ClientGUI */
        public ClientGUI() {
            initComponents();
            this.setVisible(true);
        }
    
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            TF_FilePath = new javax.swing.JTextField();
            jLabel6 = new javax.swing.JLabel();
            GetFile = new javax.swing.JButton();
            jLabel5 = new javax.swing.JLabel();
            jLabel1 = new javax.swing.JLabel();
            PutFile = new javax.swing.JButton();
            setPort = new javax.swing.JButton();
            setIP = new javax.swing.JButton();
            jLabel3 = new javax.swing.JLabel();
            TFServerIP = new javax.swing.JTextField();
            setFilePath = new javax.swing.JButton();
            TFServerPort = new javax.swing.JTextField();
            jLabel7 = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            ServerFile = new javax.swing.JList();
            jLabel8 = new javax.swing.JLabel();
            jLabel9 = new javax.swing.JLabel();
            jScrollPane3 = new javax.swing.JScrollPane();
            ClientFile = new javax.swing.JList();
            jLabel10 = new javax.swing.JLabel();
            startClient = new javax.swing.JButton();
            endClient = new javax.swing.JButton();
            jLabel2 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jScrollPane2 = new javax.swing.JScrollPane();
            ActivityLog = new javax.swing.JTextArea();
            jLabel11 = new javax.swing.JLabel();
            jLabel12 = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Clients Interface");
    
            TF_FilePath.setEditable(false);
            TF_FilePath.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    TF_FilePathActionPerformed(evt);
                }
            });
    
            jLabel6.setText("File Path");
    
            GetFile.setText("Get File >>");
            GetFile.setEnabled(false);
            GetFile.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    GetFileActionPerformed(evt);
                }
            });
    
            jLabel5.setText("Client share files");
    
            jLabel1.setText("Server IP Address :");
    
            PutFile.setText("<< Set File");
            PutFile.setEnabled(false);
            PutFile.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    PutFileActionPerformed(evt);
                }
            });
    
            setPort.setText("Set Port ");
            setPort.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    setPortActionPerformed(evt);
                }
            });
    
            setIP.setText("Set IP ");
            setIP.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    setIPActionPerformed(evt);
                }
            });
    
            jLabel3.setText("Server share files");
    
            TFServerIP.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    TFServerIPActionPerformed(evt);
                }
            });
    
            setFilePath.setText("Browse");
            setFilePath.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    setFilePathActionPerformed(evt);
                }
            });
    
            TFServerPort.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    TFServerPortActionPerformed(evt);
                }
            });
    
            jLabel7.setText("* Address entered must be same as IP address  used on server");
    
            ServerFile.setForeground(new java.awt.Color(0, 0, 255));
            jScrollPane1.setViewportView(ServerFile);
    
            jLabel8.setText("* IP Address must be a valid one , Example: 192.168.4.1");
    
            jLabel9.setText("* Port No. entered must be same as Port No. used on server");
    
            ClientFile.setForeground(new java.awt.Color(0, 0, 255));
            jScrollPane3.setViewportView(ClientFile);
    
            jLabel10.setText("* Port No. must be integer from (1025 - 655332)");
    
            startClient.setText("Start");
            startClient.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    startClientActionPerformed(evt);
                }
            });
    
            endClient.setText("End");
            endClient.setEnabled(false);
            endClient.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    endClientActionPerformed(evt);
                }
            });
    
            jLabel2.setText("Server Port :");
    
            jLabel4.setText("Activity Log: ");
    
            ActivityLog.setColumns(20);
            ActivityLog.setForeground(new java.awt.Color(0, 0, 255));
            ActivityLog.setRows(5);
            jScrollPane2.setViewportView(ActivityLog);
    
            jLabel11.setText("              ");
    
            jLabel12.setText("              ");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 820, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 40, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel1)
                                .addGap(11, 11, 11)
                                .addComponent(TFServerIP, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(6, 6, 6)
                                .addComponent(setIP, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43)
                                .addComponent(jLabel2)
                                .addGap(4, 4, 4)
                                .addComponent(TFServerPort, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)
                                .addComponent(setPort))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(390, 390, 390)
                                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(180, 180, 180)
                                .addComponent(jLabel6)
                                .addGap(13, 13, 13)
                                .addComponent(TF_FilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(setFilePath))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(234, 234, 234)
                                .addComponent(startClient, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(102, 102, 102)
                                .addComponent(endClient, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(223, 223, 223)
                                .addComponent(jLabel12))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(287, 287, 287)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(5, 5, 5)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(GetFile)
                                    .addComponent(PutFile))
                                .addGap(7, 7, 7)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 715, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(290, 290, 290)
                                .addComponent(jLabel11)))
                        .addGap(0, 40, Short.MAX_VALUE)))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 536, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 16, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(TFServerIP, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(setIP))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(TFServerPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(setPort))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(1, 1, 1)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(jLabel6))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(TF_FilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(setFilePath))
                        .addGap(5, 5, 5)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(startClient))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(endClient))
                            .addComponent(jLabel12))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addComponent(GetFile)
                                .addGap(17, 17, 17)
                                .addComponent(PutFile))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(7, 7, 7)
                        .addComponent(jLabel11)
                        .addGap(0, 16, Short.MAX_VALUE)))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void TF_FilePathActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
    }                                           
    
        private void GetFileActionPerformed(java.awt.event.ActionEvent evt) {                                        
    
            preventGUIFreezing();
            Runnable readRun = new Runnable() {
                public void run() {
                    GetFile.setEnabled(false);
                    PutFile.setEnabled(false);
                    try {
                        Socket sock2 = new Socket(serverAddress,serverPort); //CHANGE IP AND PORT
    
                        DataInputStream streamIn2 = null;
                        DataOutputStream streamOut2 = null;
    
                        //receive shares file name
                        streamIn2 = new DataInputStream(sock2.getInputStream());
                        String line = streamIn2.readUTF(); //dummy string to receive the filelist
                        //System.out.println(line);
    
                        String file = "get"+filelist2[ServerFile.getSelectedIndex()];
                        //sent selected FileName to be download
                        try {
                            streamOut2 = new DataOutputStream(sock2.getOutputStream());
                            streamOut2.writeUTF(file);
                            ActivityLog.append("Client has select file -> "+file.substring(3,file.length())+"\n");
                            streamOut2.flush();
                        } catch(Exception e) {
                            JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                        }
    
                        ActivityLog.append("Start Receiving ->"+file.substring(3,file.length())+"\n");
                        int bytesRead2;
                        int current2 = 0;
                        long start = System.currentTimeMillis();
    
                        //receive file
                        DataInputStream i2 = new DataInputStream(sock2.getInputStream());
                        int filesize2 = i2.readInt(); //READING THE FILE SIZE from sender
                        byte [] mybytearray2  = new byte [filesize2];
                        InputStream is2 = sock2.getInputStream();
                        FileOutputStream fos2 = new FileOutputStream(path+"/"+file.substring(3,file.length()));
                        BufferedOutputStream bos2 = new BufferedOutputStream(fos2);
                        bytesRead2 = is2.read(mybytearray2,0,mybytearray2.length);
                        filesize2 = filesize2 - bytesRead2;
                        current2 = bytesRead2;
                        do
                        {
                            bytesRead2 = is2.read(mybytearray2, current2, (mybytearray2.length-current2));
                            if(bytesRead2 >= 0) {
                                current2 += bytesRead2;
                            }
                            filesize2 = filesize2 - bytesRead2;
                            System.out.println(current2);
                        } while(filesize2>0);
    
                        bos2.write(mybytearray2, 0 , current2);
                        bos2.flush();
                        long end = System.currentTimeMillis();
                        ActivityLog.append("File Transfer Complete in ->"+(end-start)+"ms.\n");
                        bos2.close();
                        sock2.close();
                    } catch(Exception e) {
                        JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                    }
                    GetFile.setEnabled(true);
                    PutFile.setEnabled(true);
                }
            };
            getFileThread = new Thread(readRun);
            getFileThread.start();
    }                                       
    
        private void PutFileActionPerformed(java.awt.event.ActionEvent evt) {                                        
    
            preventGUIFreezing();
            Runnable readRun = new Runnable() {
                public void run() {
                    try {
                        GetFile.setEnabled(false);
                        PutFile.setEnabled(false);
                        Socket sock3 = new Socket(serverAddress,serverPort); //CHANGE IP AND PORT
                        DataOutputStream streamOut3 = null;
                        DataInputStream streamIn3 = null;
    
                        String file = "put"+clientFileList[ClientFile.getSelectedIndex()];
    
                        try {
                            streamOut3 = new DataOutputStream(sock3.getOutputStream());
                            //send selected file name to be upload
                            streamOut3.writeUTF(file);
                            ActivityLog.append("Client has select file -> "+file.substring(3,file.length())+"\n");
                            streamOut3.flush();
                        } catch(Exception e) {
                            System.out.println(e.getMessage());
                        }
                        sock3.close();
    
                        //1024 file sending experiment
                        Socket sock4 = new Socket(serverAddress,serverPort);
                        File myFile2 = new File(path+"/"+file.substring(3,file.length()));
    
                        //CHANGE DATAOUTPUTSTREAM TO OUTPUTSTREM
                        DataOutputStream o2 = new DataOutputStream(sock4.getOutputStream());
                        OutputStream o3 = sock4.getOutputStream();
                        FileInputStream fis2 = new FileInputStream(myFile2);
                        BufferedInputStream bis2 = new BufferedInputStream(fis2);
                        long lenth2=bis2.available(); //GET THE INITIAL FILE SIZE
                        o2.writeInt((int)lenth2); //SEND TO CLIENT TO TELL THE TOTAL FILE SIZE
                        o2.flush();
                        byte bytes[] = new byte[1024];
                        int writecount;
                        while (lenth2 > -1) {
                            if(lenth2>=1024) {
                                writecount = 1024;
                            } else {
                                writecount = (int)lenth2;
                            }
                            bis2.read(bytes, 0, writecount);
                            ActivityLog.append("Bytes left "+lenth2+"\n");
                            o3.write(bytes, 0,  writecount);
                            lenth2 = lenth2 - writecount;
                        }
                        o3.flush();
                        sock4.close();
                        //1024 file sending experiment
                        ActivityLog.append("Finish send ->"+file.substring(3,file.length())+" To server\n");
                        GetFile.setEnabled(true);
                        PutFile.setEnabled(true);
                    } catch(Exception e) {
                        JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                    }
                }
            };
            sendFileThread = new Thread(readRun);
            sendFileThread.start();
    }                                       
    
        private void setPortActionPerformed(java.awt.event.ActionEvent evt) {                                        
    
            try {
                int tempServerPort = Integer.parseInt(TFServerPort.getText());
                if(tempServerPort>1023 && tempServerPort<65535) //start from 1024 - 65534
                {
                    serverPort = tempServerPort;
                    ActivityLog.append("Port number set To -> "+serverPort+"\n");
                } else {
                    JOptionPane.showMessageDialog(null,"Please Enter The Port Number In the Range of 1024 - 65534","WARNING!!",0);
                }
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null,"Please Enter Numbers Only","WARNING!!",0);
            }
    }                                       
    
        private void setIPActionPerformed(java.awt.event.ActionEvent evt) {                                      
    
            String tempServerAddress = TFServerIP.getText();
            String [] tempServerAddress2 = new String [4];
            int octetCount = 1;
            int ipSeg = 0;
            int [] tempServerIP = new int[4];
    
            for(int j=0;j<4;j++) //INIT each array of Server Address with empty String
            {
                tempServerAddress2[j] = "";
            }
    
            for(int k=0;k<tempServerAddress.length();k++) {
                if(tempServerAddress.substring(k, (k+1)).equals(".")) {
                    octetCount++; //count the IP Entry Octet
                }
            }
            if(octetCount!=4) //If octet != 4 , its not a valid IP Entry
            {
                JOptionPane.showMessageDialog(null,"Please Enter A Valid IP Adress","Error!!!",0);
            } else {
                for(int l=0;l<tempServerAddress.length();l++) {
                    if(!tempServerAddress.substring(l, (l+1)).equals(".")) {
                        tempServerAddress2[ipSeg] = tempServerAddress2[ipSeg]+tempServerAddress.substring(l, (l+1));
                    } else {
                        ipSeg++; //change the Server Address2 Array to the next slot
                    }
                }
    
                try {
                    tempServerAddress = ""; //reset to empty String
                    for(int m=0;m<4;m++) {   //store the string array into Integer array for comparison
                        //to check whether each array of string only contain numbers
                        tempServerIP[m] = Integer.parseInt(tempServerAddress2[m]);
                        if(tempServerIP[m]>=0 && tempServerIP[m]<=255) {
                            //re-use to existing String for comparison
                            tempServerAddress = tempServerAddress+Integer.toString(tempServerIP[m])+".";
                        }
                    }
                } catch(Exception e) {
                    JOptionPane.showMessageDialog(null,"Please Enter A Valid IP Adress","Error!!!",0);
                    tempServerAddress = ""; //reset serverAddress to empty String
                }
    
                if(!tempServerAddress.equals("")) {
                    serverAddress = tempServerAddress.substring(0,(tempServerAddress.length()-1));
                    ActivityLog.append("IP Address set to ->"+serverAddress+"\n");
                }
            }
    }                                     
    
        private void TFServerIPActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
    }                                          
    
        private void setFilePathActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int returnVal = chooser.showOpenDialog(this);
            if(returnVal == JFileChooser.APPROVE_OPTION)    //if the path selected is valid
            {
                path = chooser.getSelectedFile().getPath(); //set the path into a String
    
                //update The Directory List
                File path2 = new File(path);
                File Filelist [];
                Filelist = path2.listFiles();  //set filelist = path selected
                clientFileList = new String[Filelist.length];
                for(int k=0; k<Filelist.length;k++) //fill up str array with filelist
                {
                    if(Filelist[k].isDirectory()) //if the file is directory
                    {
                        continue;
                    } else {
                        if(Filelist[k].length()<=902238600) {
                            clientFileList[k] = Filelist[k].getName();
                        }
                    }
                }
                ClientFile.setListData(clientFileList);
                TF_FilePath.setText(path);
            }
    }                                           
    
        private void TFServerPortActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
    }                                            
    
        private void startClientActionPerformed(java.awt.event.ActionEvent evt) {                                            
    
            if(serverAddress.equals("") || serverPort==0 || TF_FilePath.getText().equals("")) {
                JOptionPane.showMessageDialog(null,"Please Input a valid IP Adress and Port Number before Starting the session","Error!!!",0);
            } else {
                preventGUIFreezing();
                Runnable readRun = new Runnable() {
                    public void run() {
                        try {
                            sock = new Socket(serverAddress,serverPort);
                            streamIn = new DataInputStream(sock.getInputStream()); //get the File List from the server
                            filelist = streamIn.readUTF(); //save the file list to the
                            setIP.setEnabled(false);
                            setPort.setEnabled(false);
                            setFilePath.setEnabled(false);
                            startClient.setEnabled(false);
                            PutFile.setEnabled(true);
                            GetFile.setEnabled(true);
                            endClient.setEnabled(true);
                            if(serverStatus == 0) {
                                ActivityLog.append("Connected to Server\n");
                                serverStatus = 1;
                            }
                            //store the filelist into filelist2 array
                            filelist2 = filelist.split("\n");
    
                            ServerFile.setListData(filelist2);
                            streamIn.close();
                            sock.close();
                        } catch(Exception e) {
                            JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                        }
                    }
                };
                readThread = new Thread(readRun);
                readThread.start();
            }
    }                                           
    
        private void endClientActionPerformed(java.awt.event.ActionEvent evt) {                                          
            // TODO add your handling code here:
            JOptionPane.showMessageDialog(null,"Thank you ");
            System.exit(1);
    }                                         
    
        //DOWNLOAD FILE FROM SERVER
        //UPLOAD FILE TO SERVER
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ClientGUI().setVisible(true);
                }
            });
        }
    
        //method to make sure the threads does not lock up repainting
        public void preventGUIFreezing()
        {
             if(SwingUtilities.isEventDispatchThread())
             {
                return;
             }
             throw new RuntimeException("file");
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JTextArea ActivityLog;
        private javax.swing.JList ClientFile;
        private javax.swing.JButton GetFile;
        private javax.swing.JButton PutFile;
        private javax.swing.JList ServerFile;
        private javax.swing.JTextField TFServerIP;
        private javax.swing.JTextField TFServerPort;
        private javax.swing.JTextField TF_FilePath;
        private javax.swing.JButton endClient;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel12;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JScrollPane jScrollPane3;
        private javax.swing.JButton setFilePath;
        private javax.swing.JButton setIP;
        private javax.swing.JButton setPort;
        private javax.swing.JButton startClient;
        // End of variables declaration                   
    
    }
    Last edited by awpad; 08-04-2011 at 04:27 AM.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    300 or 400 MB it doesn't accept
    Do you get an error message? Or please explain what "doesn't accept" means.

    Please edit your code and wrap it in code tags to preserve formatting. Use the #icon above the input box.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    That's an awful lot of code to look at for what is essentially an "it doesn't work" question.
    You;re going to have to do some debugging yourself as to what is happening, like where it's hanging (if it is)...then you might be able to give us something to work with.
    awpad likes this.

  5. #5
    awpad is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    debugging , testing have been done , and it works properly
    I can send and receive files (<=70 Mb) from / to client and server
    but once i try to send more than 70 Mb it didn't
    i think the problem is here
    Java Code:
    //1024 file sending experiment
                        Socket sock4 = new Socket(serverAddress,serverPort);
                        File myFile2 = new File(path+"/"+file.substring(3,file.length()));
    
                        //CHANGE DATAOUTPUTSTREAM TO OUTPUTSTREM
                        DataOutputStream o2 = new DataOutputStream(sock4.getOutputStream());
                        OutputStream o3 = sock4.getOutputStream();
                        FileInputStream fis2 = new FileInputStream(myFile2);
                        BufferedInputStream bis2 = new BufferedInputStream(fis2);
                        long lenth2=bis2.available(); //GET THE INITIAL FILE SIZE
                        o2.writeInt((int)lenth2); //SEND TO CLIENT TO TELL THE TOTAL FILE SIZE
                        o2.flush();
                        byte bytes[] = new byte[1024];
                        int writecount;
                        while (lenth2 > -1) {
                            if(lenth2>=1024) {
                                writecount = 1024;
                            } else {
                                writecount = (int)lenth2;
                            }
                            bis2.read(bytes, 0, writecount);
                            ActivityLog.append("Bytes left "+lenth2+"\n");
                            o3.write(bytes, 0,  writecount);
                            lenth2 = lenth2 - writecount;
                        }
                        o3.flush();
                        sock4.close();
                        //1024 file sending experiment
                        ActivityLog.append("Finish send ->"+file.substring(3,file.length())+" To server\n");
                        GetFile.setEnabled(true);
                        PutFile.setEnabled(true);
                    } catch(Exception e) {
                        JOptionPane.showMessageDialog(null,"Warning:"+e.getMessage(),"WARNING!!",0);
                    }
                }
            };
            sendFileThread = new Thread(readRun);
            sendFileThread.start();
    }
    and unfortunately i couldn't figure it out

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    So?
    What is happening at that point?
    What is the system doing?
    Does it hang?
    Is it thrashing?

  7. #7
    awpad is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Yes it hangs.
    and there is no way to start a new session except terminating the program by pressing end button
    is there any way to extend size of bytes array ( I did , but didn't extend)
    or might be the loop of do while

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Your logs should show you what's going on and where it is hanging.

Similar Threads

  1. restrict file size before upload
    By javaforums187 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-20-2011, 08:57 AM
  2. Upload/download a file to/from server
    By karq in forum Networking
    Replies: 16
    Last Post: 08-24-2010, 09:43 AM
  3. How to upload a file from client to server
    By john_thomas03 in forum New To Java
    Replies: 4
    Last Post: 07-26-2010, 02:00 PM
  4. :large file upload to server(chunk upload)
    By tommy_725 in forum Networking
    Replies: 0
    Last Post: 10-16-2009, 12:21 AM
  5. upload and download file using servlet
    By amit_m04 in forum Java Servlet
    Replies: 1
    Last Post: 09-27-2009, 03:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •