943,987 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 703
  • Java RSS
Jan 15th, 2009
0

very basic sun tutorial base question

Expand Post »
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.
Similar Threads
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008
Jan 15th, 2009
0

Re: very basic sun tutorial base question

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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Jan 15th, 2009
0

Re: very basic sun tutorial base question

Click to Expand / Collapse  Quote originally posted by stephen84s ...
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.)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 15th, 2009
0

Re: very basic sun tutorial base question

Click to Expand / Collapse  Quote originally posted by masijade ...
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
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008
Jan 15th, 2009
0

Re: very basic sun tutorial base question

Click to Expand / Collapse  Quote originally posted by localp ...
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 ..
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Recursive File List - Help me problem solve please
Next Thread in Java Forum Timeline: Need Help with Java for Payroll Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC