Results 1 to 3 of 3
  1. #1
    Maygs is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default Reading output from console

    Hey, I'm coding a client and server and when I send an error message from the server to the console I want the client to read message from the console and if the first word is "ERROR" it will disconnect the client from the server.

    This is what I have but the problem with this code is instead of reading the message that the server returns to the console it just reads the first word of what the client inputted (e.g. I write "DRAW 0 50 0 599 red" and this makes the server return "ERROR parameter out of bounds" the code I wrote will read DRAW instead of ERROR).

    Java Code:
    		PrintWriter out = new PrintWriter(server.getOutputStream(), true);
    		BufferedReader in = new BufferedReader(new InputStreamReader(
    		BufferedReader stdIn = new BufferedReader(
    				new InputStreamReader(;
    		String msg;
    		while ((msg = stdIn.readLine()) != null) {
    			String[] x = msg.split(" ");
    			if (x[0].equals("ERROR")){  
    				System.out.println("You have been disconnected");
    Does anyone know how to fix this?

    Last edited by Maygs; 06-13-2013 at 06:55 PM.

  2. #2
    Maygs is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default Re: Reading output from console

    Can anyone help? Might post this in the advanced forum if no one can.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Reading output from console

    No, don't double post. Please fo through the Forum Rules.

    If you don't get a response, it's possible that nobody here knows the answer. I certainly don't.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Need help with printing console output to JTextArea
    By ShinTec in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2010, 10:10 AM
  2. output to terminal instead of console on mac
    By firen in forum Advanced Java
    Replies: 0
    Last Post: 06-01-2010, 12:42 PM
  3. How Do You?? Get the Console Output as a GUI??
    By Lyricid in forum AWT / Swing
    Replies: 10
    Last Post: 11-20-2009, 11:35 PM
  4. How to align the output on console?
    By sfe23 in forum New To Java
    Replies: 5
    Last Post: 03-30-2009, 03:28 AM
  5. Replies: 1
    Last Post: 07-24-2007, 02:02 AM

Posting Permissions

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