Solved

sockets and security violation

Posted on 1997-11-13
3
225 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 83
Oracle SQL syntax check  without executing 6 75
tomcat not starting 6 68
maven module vs maven project 3 47
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

839 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