Solved

java.net.SocketException: Unrecognized Windows Sockets error: 10106

Posted on 2004-10-28
5,022 Views
Last Modified: 2008-01-09
hi,
i open a socket in my program. when i execute this program from another program (by using Runtime.getRuntime().exec()), the problem occurs. the program i tried to open a socket gives the following exception :
java.net.SocketException: Unrecognized Windows Sockets error: 10106: create

what can be the reason? if i execute the program by itself, there is no problem..
thanks..
0
Question by:luseng
    18 Comments
     
    LVL 86

    Expert Comment

    by:CEHJ
    Why use runtime exec btw? Why not

    OtherClass.main(stringArray);

    ?
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    Or maybe it's not a Java program?
    0
     

    Author Comment

    by:luseng
     i exec 4 different programs in this program..   all of them includes Threads, System.exit(0), etc.. if i execute them by calling main, it seems to me that there can be some problems..
       
    0
     

    Author Comment

    by:luseng
    they are java programs..

     for example  : Runtime.getRuntime().exec("a.jar")
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>for example  : Runtime.getRuntime().exec("a.jar")

    That particular example, if accurate, makes no sense. Can you give the actual commands?
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>makes no sense

    I know you can 'execute' a jar by double-clicking it, but that's only on account of Windows shell integration. The command should really be

    Runtime.getRuntime().exec("java -jar a.jar")

    (if an executable jar)
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>it seems to me that there can be some problems..

    What problems? You're going to have a much better chance of remaining problem-free doing things this way than using Runtime.exec
    0
     

    Author Comment

    by:luseng
       I use the following commands :  

        String javaexec = System.getProperty("java.home") + File.separator +
                              "bin" + File.separator + "java";

         String cmd =  "\"" +javaexec + "\" -jar " + "a.jar";
                
        Runtime.getRuntime().exec(cmd , env, file);
    0
     
    LVL 86

    Accepted Solution

    by:
    Personally i would attack this problem by first lowering the complexity of invoking the programs in the first place, and that means calling their main methods. They'll also start much faster if you do that
    0
     

    Author Comment

    by:luseng
     ok...
      what about using Runtime.getRuntime().exec? what can be the reason of exception? i am  wondering that..
      thanks..
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    Have you missed my point - i'm saying to *not* use Runtime?
    0
     

    Author Comment

    by:luseng
     sorry, i missed it.  
      why not?
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    Because it's introducing a layer of complexity you don't need, that can lead to problems
    0
     

    Author Comment

    by:luseng
    ok, thanks..
    0
     
    LVL 9

    Expert Comment

    by:Venci75
    0
     

    Author Comment

    by:luseng
     do i need to call main class of a.jar?
     
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >> do i need to call main class of a.jar?

    Yes. If you want to try an interim 'quicker fix' pass all commands to Runtime.exec as a String[], not a String
    0
     
    LVL 92

    Expert Comment

    by:objects
    try running:

    cmd /c java -jar a.jar
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Cisco Complete Network Certification Training

    If you’re an IT engineer or technician, it's time you take your career to the next level. This elite training bundle is brimming with all of the information you need to learn to sit for Cisco CNNA, CCNP, and CCENT certification exams.

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now