Results 1 to 3 of 3
  1. #1
    xellos is offline Member
    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Default program is very slow

    i hava this code it works but it runs very slow

    Java Code:
    import java.net.Socket;
    import java.io.IOException;
    import java.io.*;
    
    public class portscan {
    
    
        public static void main(String[] args) throws IOException {
           int i = 0;
           String remote = "localhost";
           FileWriter fstream = new FileWriter("hello.txt");
           BufferedWriter out = new BufferedWriter(fstream);
           
           
           
           
          
           
           do {
        	   try {
        	   Socket s = new Socket(remote,i);
        	   out.write("Server is listening on port " + i+ " of " + remote );
        	   out.newLine();
        	   s.close();
    
           } catch (IOException ex) {
        	   out.write("Server is not listening on port " + i+ " of " + remote);
        	   out.newLine();
        }
           i++;
           } while(i <= 55000);
           out.close();
           
    }}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: program is very slow

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    doWhile is online now Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: program is very slow

    i hava this code it works but it runs very slow
    Define 'slow'...you are connecting to a Socket 55,000 times repetitively, and most likely thousand of exceptions are thrown in the process, how fast do you think its going to run?

Similar Threads

  1. Slow applet
    By robs in forum Java Applets
    Replies: 20
    Last Post: 02-28-2011, 03:15 PM
  2. why is it so slow? need to optimize it?
    By skarosg3 in forum Advanced Java
    Replies: 15
    Last Post: 10-08-2010, 08:54 AM
  3. my program is running bit slow!!
    By Arn00p in forum AWT / Swing
    Replies: 18
    Last Post: 05-05-2010, 04:14 PM
  4. slow iterator
    By jamborta in forum New To Java
    Replies: 9
    Last Post: 05-25-2009, 08:04 AM
  5. is IntelliJ is slow in IDE ??
    By adusumalli in forum IntelliJ IDEA
    Replies: 3
    Last Post: 12-16-2008, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •