2 Replies Latest reply on Mar 16, 2007 4:23 PM by 807597

    Port open or closed

      I need to write a program which tells weather a particular port , say 2800 is open or closed? how do i go about it?
        • 1. Re: Port open or closed
          hai i have the same problem , If u got the solution plz send me the code

          my rediff address is cuteassassin@rediffmail.com
          • 2. Re: Port open or closed
            The statement "port 2800 is open" simply means that there's an application or service running at the host machine listening on port 2800. What you want to do, is called "Port Scanning".

            Java does not support low level networking, so you have to try connecting to that port, whether it is open or closed. The following code will simply do this:
            Socket sock;
            try {
                    sock = new Socket("MyHostAddress",2800);
                    System.out.println("Ok, the port 2800 is open...");
            } catch(IOException err) {
                    System.out.println("Sorry, the port 2800 is closed...");
            More advanced and faster port scanning methods require low level networking, and cannot be done with Java.