have troulbe when learn java tutorial's network socket part

Discussion in 'Java' started by jieshuang@gmail.com, Apr 19, 2006.

  1. Guest

    Hi everyone:
    Try fewest word: from Java Turotial->Custom Networking->All About
    Sockets->Reading from and Writing to a socket, the following program:
    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("taranis", 7);
    out = new PrintWriter(echoSocket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(
    } catch (UnknownHostException e) {
    System.err.println("Don't know about host: taranis.");
    } catch (IOException e) {
    System.err.println("Couldn't get I/O for "
    + "the connection to: taranis.");

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

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


    But it says "Don't know about host: taranis". If I change it to my
    computer's name, it says "Couldn't get I/O for the connection to:
    So how can I open echo service on a computer? Thanks.
    , Apr 19, 2006
    1. Advertisements

  2. hiwa Guest

    the host name taranis. This is the name of a hypothetical machine on
    our local network.
    Try "localhost" instead.
    Also, the echo server should be running on your host.
    hiwa, Apr 19, 2006
    1. Advertisements

  3. Guest

    " Also, the echo server should be running on your host."

    I'm sorry but how can I set up the echo server on my host? I'm using
    Windows XP.
    , Apr 19, 2006
  4. wrote:
    > " Also, the echo server should be running on your host."
    > I'm sorry but how can I set up the echo server on my host? I'm using
    > Windows XP.

    You maybe better as this on a Windows group. AFAIK Windows Server
    edition has an echo server as part of the "Simple TCP/IP Services",
    which one can configure somewhere. I have no idea if there is something
    similar in XP.

    If you can't find anything, you can maybe try the very simple server
    given at the end of

    It listens on a different port, but it should be easy to change this in
    your client.

    A general remark: Sun's networking tutorial is rather bad. it is maybe
    ok for some first steps, but it is fare from complete, and has some ugly
    errors. So, you probably want to read some more about TCP/IP in general.

    Thomas Weidenfeller, Apr 19, 2006
  5. Guest

    Thank you. Echo server is not so important to me. I just want to learn
    basic network programming in serveral weeks. Your link is useful,
    although it seems that the "echo server" in it does not have port 7,
    and it still use InputDataStream which is reported as too old by javac.
    I know to be expert in network, some books like Steven's is essential.
    But you know, English is my second language and I have to work and have
    to learn to cheat for job(network and database is hot, so I have to
    learn basic of them and do several project). I have not much time.
    , Apr 19, 2006
  6. mlody277 Guest

    Hallo I am new at this group but in my opinion :
    First of all You have to create a server application at the same port
    like a client and start it than You can start the EchoClient class.
    You receive the exceptions because there is no machine( server ) which
    can serve requests from EchoClient
    The other problem is that in the line:
    echoSocket = new Socket("taranis", 7);
    you use the post = 7. The ports between 0 and 1024 are reserved for the
    system, so please use some biger number.
    If you want to lunch this cod locally at Your computer use "localhost"
    not "taranis"
    I believe that this post help You.
    Best regarst
    mlody277, Apr 19, 2006
  7. Thomas Weidenfeller, Apr 19, 2006
  8. Roedy Green Guest

    On 19 Apr 2006 01:55:43 -0700, ""
    <> wrote, quoted or indirectly quoted someone who
    said :

    >English is my second language and I have to work and have
    >to learn to cheat for job

    Some proverbs would be appropriate here.

    This approach simply does not work in computers. A brilliant
    psychologist Chris Rainey (who suddenly dropped dead of a brain tumor)
    proved this to many years ago when I was absolutely frazzled trying to
    meet deadlines.

    He persuaded me to, just as an short term experiment, be lazy and
    deliberately take too much time to complete each task.

    Of course in this relaxed environment I made very few errors and
    everything worked first time. My productivity soared. I did not have
    to do anything over. I wrote easy-to-maintain code. I stopped wasting
    time flapping my arms muttering "I HAVE to get this finished." Without
    the adrenalin, I could think clearly and logically.

    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Apr 20, 2006
  9. Guest

    Thanks you. Yes, troubles are caused by the unexisting echo server,
    whose port is 7 (but "use some biger number" if it will create a
    server, not a client, I think). I now create server myself in program
    for study purpose. Gone away echo server with port 7~~~
    , Apr 20, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Stylus Studio
    Jan 31, 2006
  2. Porky Pig Jr
    May 12, 2004
  3. CoreyWhite
    Mar 31, 2007
  4. ali
  5. dotrat1989
    Dec 2, 2008
  6. Laszlo Nagy
    Mark Wooding
    Jan 27, 2009
  7. Steve Holden
  8. Alexander
    BGB / cr88192
    Sep 11, 2010