Solved

sockets and security violation

Posted on 1997-11-13
3
220 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
Comment Utility

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
Comment Utility

 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
Comment Utility

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

771 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

13 Experts available now in Live!

Get 1:1 Help Now