1 Reply Latest reply on Jan 15, 2003 11:54 AM by 807596

    Socket Errors - Urgent

    807596
      I'm am sending files from a client to a server using a socket and server socket combination, with the buffered Input and Output stream. When I'm sending files accross using the loop back address on the local machine I have no problems and can set the byte array to any size. When I try and send across a network I have two problems
      1) - if the byte array is 1024 bytes or less it send really slowly
      2) - with a larger byte array I get an IO error - type code out of range 0

      Can any one help me with this problem, below is some sample code assume a socket connection has been set up with buffered input and output streams

      input = socket.getInputStream(); // assume this has been set up correctly


      //Method to read byte arrays from a socket
      public byte[] readBytes(byte[] bytes) throws Exception{
      try{
      input.read(bytes);
      }
      catch(IOException e){
      // this is the excption I am always getting
      throw new Exception("An IO Error has Occured: " + e.getMessage());
      }
      return bytes;
      }

      //Sample block of code to recieve files

      String response = "";
                File real = new File(".\\Shared\\" +fileName);
                File temp = new File(".\\Shared\\temp" +fileName);
                temp.createNewFile(); // ensure files are not overwritten if canceled by creating a temporary file

                boolean canceled = false;

                FileOutputStream output = new FileOutputStream(temp);

                response = (String) readObject(); // recieve size of file

                int numberOfBytes = Integer.parseInt(response);
                sendObject("ACK");
                byte[] bytes;

                while(!response.equalsIgnoreCase("Finished") && !response.equalsIgnoreCase("Quit")){
                     response = (String) readObject();
                     if(response.equalsIgnoreCase("Quit")){ //cancel upload if user send quit
                          canceled = true;
                          output.close();
                          temp.delete();
                          break;
                     }
                     else if(!response.equalsIgnoreCase("Finished")){
                          bytes = new byte[Integer.parseInt(response)];
                          bytes = readBytes(bytes); //recieve bytes
                          output.write(bytes); //output bytes
                          dl.increaseProgress(); // this is the progress bar ignore this
                          sendObject("ACK");
                     }
                }

        • 1. Re: Socket Errors - Urgent
          807596
          Hi Duncan,

          did u encounter any problem with the socket exception? coz when i connect server-client, i received the following error:
          java.security.AccessControlException: access denied (java.net.SocketPermission 10.0.0.7:7000 connect,resolve)
                  at java.security.AccessControlContext.checkPermission(AccessControlConte
          xt.java:270)
                  at java.security.AccessController.checkPermission(AccessController.java:
          401)
                  at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)