Reputation: 21
I'm trying to make a simple telnet client, using Sockets in java. Here is what I've written:
public class NetUtil {
public static void main(String[] args) throws IOException {
Socket sock = new Socket("localhost", 23);
InputStream in = sock.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String output;
while((output=br.readLine())!=null){
System.out.println(output);
}
}
}
The problem is that output freezes when trying to read from buffered reader. I've checked connection with sock.isConnected() - its connected. My telnet server is up and running - i've checked from console - i can connect to my workstation, but when i try using sockets, it fails.
Upvotes: 1
Views: 788
Reputation: 1303
I don't think you should reinvent the wheel here. Try using Apache Commons Net telnet client.
Upvotes: 1
Reputation: 9776
Are you sure, that the server sends something? Does it send newline character as well? Your program is expecting it with calling readLine
of BufferedReader
.
Upvotes: 0