Results 1 to 4 of 4
Thread: need to explain this code
- 12-03-2007, 09:31 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
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); }
- 12-03-2007, 09:41 PM #2
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.'
- 12-03-2007, 09:59 PM #3
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
thank very much
but is it possible to put if action without {}:
Java Code:if(lineRead.equals("Exit")) break;
- 12-03-2007, 10:01 PM #4
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Need Help Can anyone explain what this means
By Clemenza1983 in forum New To JavaReplies: 6Last Post: 02-16-2008, 03:13 AM -
Can anyone briefy explain what does that mean?
By Clemenza1983 in forum New To JavaReplies: 6Last Post: 01-29-2008, 07:05 AM -
May someone explain what these things means in Java
By quickfingers in forum New To JavaReplies: 2Last Post: 01-26-2008, 05:45 AM -
Iam new in Java Please explain to me
By vinaytvijayan in forum AWT / SwingReplies: 1Last Post: 12-30-2007, 11:35 AM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks