I have this small test socket connection class:-
import java.net.Socket;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
public class TestTelnet {
public static void main(String args[]) throws Exception {
Telnet telnet = new Telnet();
Socket socket = null ;
socket = new Socket("localhost", 23);
socket.setKeepAlive(true);
BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
System.out.println(r.readLine());
socket.close();
}
}
It works perfectly well when I use another port (for example 25 for SMTP) and the println of r.readLine works brilliantly. I can also connect to port 23 via the command prompt (telnet localhost 23) and I get the following returned:-
Ubuntu 8.10 my-laptop login:
But when I try and connect to port 23 using my java class, it just hangs on the readLine println. Does anyone know why this is?