Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2007, 10:31 PM
Member
 
Join Date: Dec 2007
Posts: 5
reached is on a distinguished road
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 !!!

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); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2007, 10:41 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
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.'
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2007, 10:59 PM
Member
 
Join Date: Dec 2007
Posts: 5
reached is on a distinguished road
thank very much
but is it possible to put if action without {}:
Code:
if(lineRead.equals("Exit")) break;
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-03-2007, 11:01 PM
Member
 
Join Date: Dec 2007
Posts: 5
reached is on a distinguished road
but i am still wondering why 2 loops ?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help Can anyone explain what this means Clemenza1983 New To Java 6 02-16-2008 04:13 AM
Can anyone briefy explain what does that mean? Clemenza1983 New To Java 6 01-29-2008 08:05 AM
May someone explain what these things means in Java quickfingers New To Java 2 01-26-2008 06:45 AM
Iam new in Java Please explain to me vinaytvijayan AWT / Swing 1 12-30-2007 12:35 PM
Generating Code Automatically Using Custom code Template In Eclipse JavaForums Eclipse 1 04-26-2007 04:52 PM


All times are GMT +3. The time now is 11:35 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org