• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

not able to enter selection on servlet

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI I hope I can get some help on this :
I have a class called protocol in which i specify the appearance and what each selection does and I have this class called :
public class Client
{
private boolean status = true;
private PrintWriter out = null;
private BufferedReader in = null;
private Socket assignSocket = null;
private String host;


public static void main(String[] args) throws IOException
{
Client cc = new Client();
cc.runClient(args);
}

private void runClient(String[] args) throws IOException
{
if (args.length == 0)
{
host = "localhost";
}
else
{
host = args[0];
}

try
{
assignSocket = new Socket("localhost", 4444);
out = new PrintWriter(assignSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader
(assignSocket.getInputStream()));
}
catch (UnknownHostException e)
{
System.err.println("Doesn't know about host: " + host);
e.printStackTrace();
return;

}
catch (IOException e)
{
System.err.println("Couldn't get I/O for the connection to: " +
host);
e.printStackTrace();
return;
}

BufferedReader stdIn = new BufferedReader(new InputStreamReader
(System.in));
String fromServer;
String fromUser = null;

while (true)
{
fromServer = in.readLine();
System.out.println(fromServer);
while (true)
{
fromServer = in.readLine();
if (fromServer == null)
{
System.out.println("fromServer was null");
break;
}

System.out.println(fromServer);

if (fromServer.equals("Bye"))
{
status = false;
break;
}
}
if (status == false)
{
break;
}

if (fromUser != null)
{
fromUser = stdIn.readLine();
out.println(fromUser);
}
}
out.close();
in.close();
stdIn.close();
assignSocket.close();
}
}
I think part of my problem is I can't break out of the loop but... i am not sure what i am doing wrong or omitting.
any suggestions would be great.

valarie
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I had a quick look at your code and I'm gonna assume the problem is in your while (true) loops .. seems a likely place to look!

As an aside would you consider putting the line


in instead of the



It'll make the code a bit less prone to problems.

Next on your inner loop you search for "bye"


and that is the only way out of the loop. You might want to have a look at that.
Also do you really need the nested while loop. Have a look at this part of the code and post back if you're still having problems,
Barry
 
reply
    Bookmark Topic Watch Topic
  • New Topic