Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Communication between C++ app and Java

Communication between C++ app and Java

Scheduled Pinned Locked Moved C / C++ / MFC
c++javasecurityhelpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kuniva
    wrote on last edited by
    #1

    Hi, i need a way to communicate between my app which is written in C++ and Java. The problem is, the application that runs the java code is not mine and it just runs the java code in a safe environment. This poses some security restrictions such as, i can't open any sockets, and seeings that was the obvious way to me to make them communicate, i don't know what to try next. Are there any facilities in Java to make communication with another windows application easier? Thanks in advance for any responses. Kuniva --------------------------------------------

    T A 2 Replies Last reply
    0
    • K Kuniva

      Hi, i need a way to communicate between my app which is written in C++ and Java. The problem is, the application that runs the java code is not mine and it just runs the java code in a safe environment. This poses some security restrictions such as, i can't open any sockets, and seeings that was the obvious way to me to make them communicate, i don't know what to try next. Are there any facilities in Java to make communication with another windows application easier? Thanks in advance for any responses. Kuniva --------------------------------------------

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      What do you exactely want to do upon the java application? Wouldn't signal sends work ?


      TOXCCT >>> GEII power

      K 1 Reply Last reply
      0
      • K Kuniva

        Hi, i need a way to communicate between my app which is written in C++ and Java. The problem is, the application that runs the java code is not mine and it just runs the java code in a safe environment. This poses some security restrictions such as, i can't open any sockets, and seeings that was the obvious way to me to make them communicate, i don't know what to try next. Are there any facilities in Java to make communication with another windows application easier? Thanks in advance for any responses. Kuniva --------------------------------------------

        A Offline
        A Offline
        antlers
        wrote on last edited by
        #3

        I'm going to pretend to be an expert on this because I just hooked up a browser-based Java application to a complex C++ library using JNI. To get meaningful communication between the Java applet and your C++ application, you are probably going to need to remove the security restrictions on the applet so it runs outside the browser's sandbox. You can do this by signing the applet with a cryptographic signature, or by running the Java code as an application instead of an applet. Once you do this, the Java app and your C++ app can communicate by sockets, or writing files to the local filesystem, or you could use JNI (or COM if the applet is written for the Microsoft VM) and package your C++ app as a DLL that the Java applet can call. If you can't or don't want to change the security restrictions on the Java applet, pretty much the only way to get it to communicate is to have both it and your C++ app talk to the same server on the applet's host (I suppose you could also send Windows messages to the applet's window, but that's a really limited form of communication). Applets are allowed to open a socket, but only back to a server on the host from which they were downloaded. Hosting the applet on your local machine might work for you as well.

        K 1 Reply Last reply
        0
        • T toxcct

          What do you exactely want to do upon the java application? Wouldn't signal sends work ?


          TOXCCT >>> GEII power

          K Offline
          K Offline
          Kuniva
          wrote on last edited by
          #4

          What exactly are signal sends? Never heard of them.. Kuniva --------------------------------------------

          1 Reply Last reply
          0
          • A antlers

            I'm going to pretend to be an expert on this because I just hooked up a browser-based Java application to a complex C++ library using JNI. To get meaningful communication between the Java applet and your C++ application, you are probably going to need to remove the security restrictions on the applet so it runs outside the browser's sandbox. You can do this by signing the applet with a cryptographic signature, or by running the Java code as an application instead of an applet. Once you do this, the Java app and your C++ app can communicate by sockets, or writing files to the local filesystem, or you could use JNI (or COM if the applet is written for the Microsoft VM) and package your C++ app as a DLL that the Java applet can call. If you can't or don't want to change the security restrictions on the Java applet, pretty much the only way to get it to communicate is to have both it and your C++ app talk to the same server on the applet's host (I suppose you could also send Windows messages to the applet's window, but that's a really limited form of communication). Applets are allowed to open a socket, but only back to a server on the host from which they were downloaded. Hosting the applet on your local machine might work for you as well.

            K Offline
            K Offline
            Kuniva
            wrote on last edited by
            #5

            Well the problem is that the java code is not running in a browser and its not an applet, its just.. scripts running through JNI already by another application, so i can write the scripts, but not change the application. So i want to communicate with the scripts. Kuniva --------------------------------------------

            A 1 Reply Last reply
            0
            • K Kuniva

              Well the problem is that the java code is not running in a browser and its not an applet, its just.. scripts running through JNI already by another application, so i can write the scripts, but not change the application. So i want to communicate with the scripts. Kuniva --------------------------------------------

              A Offline
              A Offline
              antlers
              wrote on last edited by
              #6

              If code you don't control is putting the Java code in a restricted sandbox, there isn't a lot you can do (that's what the sandbox features is for, after all). Do you know the details of the sandbox restrictions? Do you get a SecurityException when you try to connect to a local socket from the Java?

              K 1 Reply Last reply
              0
              • A antlers

                If code you don't control is putting the Java code in a restricted sandbox, there isn't a lot you can do (that's what the sandbox features is for, after all). Do you know the details of the sandbox restrictions? Do you get a SecurityException when you try to connect to a local socket from the Java?

                K Offline
                K Offline
                Kuniva
                wrote on last edited by
                #7

                Yes thats exactly how it is. But when i try to make a socket, i just get an error, not an exception i think, the code is basically like this:

                    try
                    {
                   		ds = new Socket(InetAddress.getByName("localhost"),port);
                	
                
                    }
                catch(UnknownHostException uhe)
                {}
                catch(IOException ie)
                {}
                   	catch(Error e)
                   	{
                   		CodexConsole.Print(0,1,"Error");
                   	}
                

                And i always get the error. I looked at the definition of JNI_CreateJavaVM and there's like three parameters u pass right? Well i might be able to "crack" them out of the java container application if i know what to change, but i'm not sure.. Would that work? if i could somehow lift the restrictions? Thanks for your help. Kuniva --------------------------------------------

                A 1 Reply Last reply
                0
                • K Kuniva

                  Yes thats exactly how it is. But when i try to make a socket, i just get an error, not an exception i think, the code is basically like this:

                      try
                      {
                     		ds = new Socket(InetAddress.getByName("localhost"),port);
                  	
                  
                      }
                  catch(UnknownHostException uhe)
                  {}
                  catch(IOException ie)
                  {}
                     	catch(Error e)
                     	{
                     		CodexConsole.Print(0,1,"Error");
                     	}
                  

                  And i always get the error. I looked at the definition of JNI_CreateJavaVM and there's like three parameters u pass right? Well i might be able to "crack" them out of the java container application if i know what to change, but i'm not sure.. Would that work? if i could somehow lift the restrictions? Thanks for your help. Kuniva --------------------------------------------

                  A Offline
                  A Offline
                  antlers
                  wrote on last edited by
                  #8

                  The restrictions aren't put in when the VM is started, but sometime later with a call to System.setSecurityManager

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups