very basic sun tutorial base question

Thread Solved

Join Date: Apr 2008
Posts: 102
Reputation: localp is an unknown quantity at this point 
Solved Threads: 2
localp localp is offline Offline
Junior Poster

very basic sun tutorial base question

 
0
  #1
Jan 15th, 2009
i am trying out this code that i got from one of suns tutorials, it deals with echoing an input back to the command prompt.

this is where i got the code
http://java.sun.com/docs/books/tutor...ngWriting.html

this is my code, and i am getting the message "Couldn't get I/O for the connection to: 127.0.0.1" printed on the screen.. i think that i might have made a mistake while editing the hostname and port name, please look in to this and help me with the working code ..

import java.io.*;
import java.net.*;

public class EchoClient {
    public static void main(String[] args) throws IOException {

        Socket echoSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;

        try {
            echoSocket = new Socket("localhost",7);
            out = new PrintWriter(echoSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
        } catch (UnknownHostException eoo) {
            System.err.println("Don't know about host: 127.0.0.1");
            System.exit(1);
        } catch (IOException eo) {
            System.err.println("Couldn't get I/O for the connection to: 127.0.0.1");
            System.exit(1);
        }

	BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
	String userInput;

	while ((userInput = stdIn.readLine()) != null) {
	    out.println(userInput);
	    System.out.println("echo: " + in.readLine());
	}

	out.close();
	in.close();
	stdIn.close();
	echoSocket.close();
    }
}
Last edited by localp; Jan 15th, 2009 at 9:13 am.
Local P ...
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: very basic sun tutorial base question

 
0
  #2
Jan 15th, 2009
The above code requires that your system have an Echo-Server installed on your system.
Echo-Servers normally listen on port "7" and give back whatever you write on their socket.

If you are on any Microsoft OS chances are that no such server exists on your system. You can also test the presence of an echo server by typing "telnet localhost 7" on your command line and see if it connects. If it displays "Connection Refused", then thats a confirmation that there is no echo server on your system.

However I remember someone posting code for a custom Echo-Server on these forums, if you do a search then you should find it.
Last edited by stephen84s; Jan 15th, 2009 at 9:46 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,358
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: very basic sun tutorial base question

 
0
  #3
Jan 15th, 2009
Originally Posted by stephen84s View Post
If you are on any Microsoft OS chances are that no such server exists on your system. You can also test the presence of an echo server by typing "telnet localhost 7" on your command line and see if it connects. If it displays "Connection Refused", then thats a confirmation that there is no echo server on your system.
And, if you're on a system owned by a company (rather than your own personal) then that server has probably been disabled, regardless of the OS. ;-)

(Most Security guidelines require the disabling of that service.)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 102
Reputation: localp is an unknown quantity at this point 
Solved Threads: 2
localp localp is offline Offline
Junior Poster

Re: very basic sun tutorial base question

 
0
  #4
Jan 15th, 2009
Originally Posted by masijade View Post
And, if you're on a system owned by a company (rather than your own personal) then that server has probably been disabled, regardless of the OS. ;-)

(Most Security guidelines require the disabling of that service.)

i am using my own PC, and its not connected to any network
Local P ...
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 102
Reputation: localp is an unknown quantity at this point 
Solved Threads: 2
localp localp is offline Offline
Junior Poster

Re: very basic sun tutorial base question

 
0
  #5
Jan 15th, 2009
Originally Posted by localp View Post
i am using my own PC, and its not connected to any network

Is there any way i could make this program running .. my ultimate goal is to communicate with other machines, located in another geographical location (using the internet), so this is my first step.. and i am very new to java , so please help me ..
Local P ...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC