Results 1 to 15 of 15
  1. #1
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default How to handle socket Exception

    Sir i am running this code on windows vista, but i am getting the Socket Exception: Permission Denied:: Listen failed.I am trying to run this application on port 8080.On this very port i am running tomcat6.0,so even when i changed the port same exception arises.
    Similar Exceptions were there when i run tomcat6.0 but when i installed tomcat6.0 as a service it worked fine.
    So, please sir what should i do run this code on my machine.
    I have Java SE(TM)Run Time Environment6 running, also mcafee antivirus running.Please post me a solution if possible
    import java.io.IOException;
    import java.net.*;

    public class SocketTest
    {

    /**
    * @param args
    */
    public static void main(String[] args)
    {

    ServerSocket myService;

    try
    {
    myService = new ServerSocket(8080);
    System.out.println("successfully opened a socket");

    }
    catch (IOException e)
    {
    e.printStackTrace();
    System.out.println(e);
    }


    }

    }

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Either mcafee or windows firewall .. if 8080 is already used it will throw BindException .. You can catch that as well before IOException.
    Paste StackTrace so that we can be sure on this ..

    happy socketing ..
    dont worry newbie, we got you covered.

  3. #3
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default Socket Exception

    The StackTrace is::
    java.net.SocketException: Permission denied: listen failed
    at java.net.PlainSocketImpl.socketListen<Native Method>
    at java.net.PlainSocketImpl.listen<Unknown Source>
    at java.net.SeverSocket.bind<Unknown Source>
    at java.net.SeverSocket.<init><Unknown Source>
    at java.net.SeverSocket.<init><Unknown Source>
    at SocketTest.main<socketTest.java:17>
    java.net.SocketException:Permission denied: listen failed

  4. #4
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    May be you dont have permission to open that port. Try run as Administrator .. If you are using cmd line .. type cmd in Start menu search bar and run cmd as administrator from there..

    Let me know ..
    dont worry newbie, we got you covered.

  5. #5
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    I tried in my Vista .. showed firewall warning and application ran without problem ..
    dont worry newbie, we got you covered.

  6. #6
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by roots View Post
    I tried in my Vista .. showed firewall warning and application ran without problem ..
    Same Exception even when i ran cmd-prompt as an administartor.
    One more thing is that i have my windows firewall settings turned off, should i make any changes in that i.e make it on.
    What should i do ?? Do tell me i am fet up of this exception. Is there a problem with the O.S.
    Similar problems as i told u were there with the tomcat6.0. But with some discussion when i installed tomcat as a service and ran as an administartor, problem vanished totally.
    But here no such result as yet.I don't think that there is a problem with the code that i posted.

  7. #7
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    :confused:
    Quote Originally Posted by roots View Post
    I tried in my Vista .. showed firewall warning and application ran without problem ..
    Now even i have changed the firewall settings.
    Still the result is the same.........
    Help me out............

  8. #8
    FredJavaFreak is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default

    Make sure port 8080 is not in use...

    check it with the netstat command...

  9. #9
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by FredJavaFreak View Post
    Make sure port 8080 is not in use...

    check it with the netstat command...
    Yes i have checked the port , it's free.
    Is there any issue with the firewall settings, or with the mcafee settings. Do tell me , so that i could make necessary changes.

  10. #10
    FredJavaFreak is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default

    Can you try to make your program listen on another port?

    Lets say for example 8889

    Does it work then?

  11. #11
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by FredJavaFreak View Post
    Can you try to make your program listen on another port?

    Lets say for example 8889

    Does it work then?
    Yes i have changed the port , but it's not running . The result is the same.
    now what should i do???

  12. #12
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by roots View Post
    I tried in my Vista .. showed firewall warning and application ran without problem ..
    I ran cmd-prompt as an administrator but it still shows the same exceptions.
    what should i do????

  13. #13
    Sreejesh is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default Might be the prolem with the IDE

    If you are using eclipse IDE or a similar one exit from the IDE and try running the code again.

  14. #14
    mayank0512 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Sreejesh View Post
    If you are using eclipse IDE or a similar one exit from the IDE and try running the code again.
    No i am not using eclipse. I sit an issue related with the mcafee antivirus settings.

  15. #15
    lilfrenchy201 is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Unhappy Help!!!!!

    oh my god please help me. what is this java.net.SocketException thing please tell me and tell me how to fix it. it is pising me of soooooooooooooo much:mad::mad::mad::mad::mad::mad::mad::mad::mad:. so please helppppppppppppppp :(

Similar Threads

  1. [SOLVED] Handle own exception
    By stevemcc in forum New To Java
    Replies: 3
    Last Post: 04-10-2008, 05:55 AM
  2. Replies: 1
    Last Post: 03-08-2008, 07:41 PM
  3. Better way to handle exceptions
    By javaplus in forum Advanced Java
    Replies: 2
    Last Post: 01-16-2008, 07:47 PM
  4. handle wrong input int/null
    By Camden in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 10:37 PM
  5. how to handle exceptions
    By paty in forum Advanced Java
    Replies: 2
    Last Post: 08-05-2007, 05:17 AM

Posting Permissions

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