Solved

sockets and security violation

Posted on 1997-11-13
3
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

691 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