Solved

sockets and security violation

Posted on 1997-11-13
3
226 Views
Last Modified: 2010-04-16
I have a java application which is running outside IIS on a server
  (the server allow just applet's downloading) and when I'm tryng to
  connect to the server with a java application on the client side
  everything works well. The lines are:

   s=new Socket(name,1183);
   System.out.println("OK");

   on client's side ( name is the valid host name )

   However when I'm turning this application into an applet, when
   I'm placing it on the server (the root diretory of IIS,
   D:\InetPub\wwwroot ) and when I'm opening a connection to the
  .html that contain it, the applet is retrieve but I have a secu-
   rity violation for these lines:

   InetAddress st=InetAddress.getLocalHost();
   s=new Socket(st,1183);

   ( I don't believe I can open it with the direct name from an
    applet)

   The java application run in the directory
   D:\InetPub\wwwroot\java

   any idea?
0
Comment
Question by:jfbe
  • 2
3 Comments
 
LVL 4

Expert Comment

by:rembo
ID: 1230482

The problem is that the Security Manager in Netscape
(or IE for that matter) will *only* allow you to
connect back to the system that you were loaded
from.  

The only exception too this rule is the showDocument()
method.  This causes the browser to load another document
which can be from anywhere.  

So, you will have to move that application to the same
server as your browser or you will have to load the applet
from the same host as the server.

-Tony

0
 

Author Comment

by:jfbe
ID: 1230483

 No, as I explained in my question my applet is coming from the same server where the application is running. I got a clue when I
output to the screen the result of:

InetAddress st=InetAddress.getLocalHost();
 st.toString() do not give me the host name but something that looks like my email.
I'll try with getDocumentBase().getHost()) later but it wasn't
the reason.
0
 
LVL 4

Accepted Solution

by:
rembo earned 100 total points
ID: 1230484

getLocalHost() will not give you the right answer in an
applet.

getCodeBase() or getDocumentBase().getHost() will do
what you want:

Socket s = (getCodeBase().getHost(), port);

That will do it.


0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example 17 59
mysql jsp example issue 32 74
how to debug htl and js pages 8 57
Html split(text) 2 32
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

733 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