Simple Networking Question?

P

Peter D

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
 
M

Matt Humphrey

Peter D said:
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 (e-mail address removed) http://www.iviz.com/
 
S

Sudsy

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?
 
M

Matt Humphrey

Sudsy said:
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.


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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top