Results 1 to 4 of 4
  1. #1
    reached is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

    Default need to explain this code

    hi
    this is the most complicated try block i have ever seen
    actually i am struggling to understand it
    there is a while loop inside another while loop !!!

    Java Code:
     try {
                    ServerSocket ss= new ServerSocket(2000);
                          while(true){
                            Socket s=ss.accept();
                            connectionCount++;
                            System.out.println("Connection "+connectionCount+" made");
                            is=s.getInputStream();
                            os=s.getOutputStream();
                            pw=new PrintWriter(os,true);
                            br=new BufferedReader(new InputStreamReader(is));
                            System.out.println("System set up");
    
                            //Read and process names until the client tells the server
                            //the sevice is no longer required.
                            lineRead="";
                            while(true){
                              lineRead=br.readLine();
                              if(lineRead.equals("Exit")) break;
                              o=names.get(lineRead);
                              if(o==null) reply="User not known";
                                else reply=(String)o;
                              pw.println(reply);
                            }
                            pw.close();
                            br.close();
                            is.close();
                            os.close();
                            System.out.println("Closed down");
                          }
                    }
                    catch(IOException e){
                      System.out.println("Trouble with connection"+e);
                    }

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    The inner while loop condition is set to true. This forces the loop to repeat until a break is encountered. This happens when the BufferedReader reads a line that says 'Exit.'

  3. #3
    reached is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

    Default

    thank very much
    but is it possible to put if action without {}:
    Java Code:
    if(lineRead.equals("Exit")) break;

  4. #4
    reached is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Need Help Can anyone explain what this means
    By Clemenza1983 in forum New To Java
    Replies: 6
    Last Post: 02-16-2008, 04:13 AM
  2. Can anyone briefy explain what does that mean?
    By Clemenza1983 in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 08:05 AM
  3. May someone explain what these things means in Java
    By quickfingers in forum New To Java
    Replies: 2
    Last Post: 01-26-2008, 06:45 AM
  4. Iam new in Java Please explain to me
    By vinaytvijayan in forum AWT / Swing
    Replies: 1
    Last Post: 12-30-2007, 12:35 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

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