Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can I connect to my Java server program using the telnet?

807601Dec 17 2007 — edited Dec 18 2007
Here's my Java server program, wich expects a cliente to be connected with it. The question is, using command line can I connect to this server program using telnet? If I do, what's the command I must use to do so?
import java.io.*;
import java.net.*;

public class Server {

   public static void main(String args[]) {
   
      try {
         ServerSocket serverSocket = new ServerSocket(4433);
         Socket socket = null;
   
         while(true) {
            System.out.print("Waiting connection...");
            socket = serverSocket.accept();
            System.out.println("Connected!");
            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintStream output = new PrintStream(socket.getOutputStream());
            String line = input.readLine();
            
            while(line != null && ! line.trim().equals("")) {
               output.println("You have sent me: " + line);
               line = input.readLine();
            }
            socket.close();
         }
      }
      catch(IOException ioe) {
          System.out.println(ioe);
      }
 
   }

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2008
Added on Dec 17 2007
2 comments
377 views