Simple Networking Question?

Discussion in 'Java' started by Peter D, Dec 2, 2003.

  1. Peter D

    Peter D Guest

    Hi,
    I tried to get the example EchoServer program from the java.sun.com website
    to work.

    It throws an IOException. Is this something to do with my PC setup. I'm
    running Red Hat 7.2 on a PC.

    The code is as follows?

    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("144.57.3.11", 7);
    out = new PrintWriter(echoSocket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(
    echoSocket.getInputStream()));
    } catch (UnknownHostException e) {
    System.err.println("Don't know about host: 144.57.3.11");
    System.exit(1);
    } catch (IOException e) {
    System.err.println("Couldn't get I/O for "
    + "the connection to: 144.57.3.11");
    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();
    }
    }


    Thanks for any help
    Pete
     
    Peter D, Dec 2, 2003
    #1
    1. Advertising

  2. "Peter D" <nospam@127.0.0.1> wrote in message
    news:3fccf73b$...
    > Hi,
    > I tried to get the example EchoServer program from the java.sun.com

    website
    > to work.
    >
    > It throws an IOException. Is this something to do with my PC setup. I'm
    > running Red Hat 7.2 on a PC.
    >
    > The code is as follows?
    >
    > 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("144.57.3.11", 7);



    On *nix systems, ports below 1024 typically are privileged--you must be root
    to use them. Switch to a higher port while you're testing.

    Cheers,
    Matt Humphrey http://www.iviz.com/
     
    Matt Humphrey, Dec 2, 2003
    #2
    1. Advertising

  3. Peter D

    Sudsy Guest

    Matt Humphrey wrote:
    > "Peter D" <nospam@127.0.0.1> wrote in message
    > news:3fccf73b$...
    >
    >>Hi,
    >>I tried to get the example EchoServer program from the java.sun.com

    >
    > website
    >
    >>to work.
    >>
    >>It throws an IOException. Is this something to do with my PC setup. I'm
    >>running Red Hat 7.2 on a PC.


    Okay, two birds with one stone! If you take a look at /etc/inetd.conf
    you'll probably find that echo is commented-out by default, vis:

    #echo stream tcp nowait root internal
    #echo dgram udp wait root internal

    Remove the comment characters and send hangup (SIGHUP) to inetd.
    Or you can issue the 'telinit q' command. You'll have to be root
    (superuser) both to edit the /etc/inetd.conf file and to send a
    signal to inetd.

    > On *nix systems, ports below 1024 typically are privileged--you must be root
    > to use them. Switch to a higher port while you're testing.


    Matt, you misunderstand the restriction. You can't BIND to
    privileged ports (i.e. open a server socket) if you're not
    running as root. Nothing wrong with trying to CONNECT to
    them, which is what Peter is trying to do.
    When you request a web page from a server you're connecting
    to port 80. Telnet uses port 23. E-mail (SMTP) uses port 25.
    No problem, right?
     
    Sudsy, Dec 3, 2003
    #3
  4. "Sudsy" <> wrote in message
    news:...
    > Matt Humphrey wrote:
    > > "Peter D" <nospam@127.0.0.1> wrote in message
    > > news:3fccf73b$...
    > >
    > >>Hi,
    > >>I tried to get the example EchoServer program from the java.sun.com

    > >
    > > website
    > >
    > >>to work.
    > >>
    > >>It throws an IOException. Is this something to do with my PC setup. I'm
    > >>running Red Hat 7.2 on a PC.

    >
    > Okay, two birds with one stone! If you take a look at /etc/inetd.conf
    > you'll probably find that echo is commented-out by default, vis:
    >
    > #echo stream tcp nowait root internal
    > #echo dgram udp wait root internal
    >
    > Remove the comment characters and send hangup (SIGHUP) to inetd.
    > Or you can issue the 'telinit q' command. You'll have to be root
    > (superuser) both to edit the /etc/inetd.conf file and to send a
    > signal to inetd.
    >
    > > On *nix systems, ports below 1024 typically are privileged--you must be

    root
    > > to use them. Switch to a higher port while you're testing.

    >
    > Matt, you misunderstand the restriction. You can't BIND to
    > privileged ports (i.e. open a server socket) if you're not
    > running as root. Nothing wrong with trying to CONNECT to
    > them, which is what Peter is trying to do.
    > When you request a web page from a server you're connecting
    > to port 80. Telnet uses port 23. E-mail (SMTP) uses port 25.
    > No problem, right?


    Ha ha. Boy, I read that late at night and thought he was writing an echo
    server. Thanks for fixing all the problems.

    Cheers,
     
    Matt Humphrey, Dec 3, 2003
    #4
    1. Advertising

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. John Galt
    Replies:
    1
    Views:
    709
    zzyzx
    Jul 15, 2004
  2. Raza S. Ali

    Networking Question

    Raza S. Ali, Jul 21, 2004, in forum: C Programming
    Replies:
    1
    Views:
    287
    Christopher Benson-Manica
    Jul 21, 2004
  3. TK
    Replies:
    5
    Views:
    300
  4. Greg Chambers
    Replies:
    12
    Views:
    194
    Joel VanderWerf
    Jul 8, 2009
  5. Replies:
    3
    Views:
    98
    Chris Angelico
    Apr 18, 2014
Loading...

Share This Page