Solved

Socket-connection from an applets init()

Posted on 1998-09-02
4
279 Views
Last Modified: 2010-03-30
When I create a socket in the init()-method of my applet, there occures a SecurityExceptionEx(Host):cannot access 'port'
This exception only occures when I load the html-page from my local machine - when I load it from the server the connection succeed.
All class-files are stored on my local machine (also the applet)
What does I have to configure on my local machine?
0
Comment
Question by:Hugi
4 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1223293
Hugi, the problem is that when you run it locally, your machine is both the client and the server. That may cause on some browsers to refuse to load images and to open socket connections. What you can do is to
1. In order to test your applet use appletviewer.
2. If you insist on using a browser, install one of the tiny freeware http servers on your machine, and activate your applet from "the server" that actually operates on the same machine.
In order to find small basic http server serch in:
www.gamelan.com
www.developer.com
www.download.com

Hope that helps, G.
0
 

Author Comment

by:Hugi
ID: 1223294
appletviewer does not work and I don't want to set up my local machine as a web-server.
0
 

Expert Comment

by:iliya
ID: 1223295
There is one limitation which can cause the problem:
The applet in the browser (like Netscape or IE) can create connection only with the site with the server, from which the HTML page is loaded.
And what socket you create in your applet? To which IP address and port you try to connect?
0
 
LVL 1

Accepted Solution

by:
Twix earned 100 total points
ID: 1223296
Hello Hugi,

You are looking at a couple of different issues here:
1.)The web browser you are using creates a different security model depending where the applet is loaded from. Applets are designed from the aspect of loading off a Server. Not running a server may mean the applet may not behave as expected.

2.) You will still have to use relitive URL's for all the files you load. This should get you past any security restrictions there. If you are having to package classes, be abolutly sure that they are found only, only, only in the directory structure below the applet. If they are found anywhere else on the class path it will not work. (You don't have to worry about the JDK classes as long as the ones from your browser company are the only ones loaded).

3. If you make a connection, it may have to be to 127.0.0.1. If you load it off the local file system, local host may be the only IP you can connect to. If security is turrned on in applet viewer this is the case. If it is turrned off, it can connect anywhere.

For IE, and Netscape, you cannot set Via the GUI low enough security restrictions to connect anywhere. For IE, I have a .reg file that I can e-mail to you if you like that will enable this.
For Netscape, you will have to check their documentation on how to enable this.

e-mail me at todde@rio.com if you want the .reg file for IE!

Twixter
Java Smarty Guy/Programer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 54
eclipse apache tomcat admin console 52 147
tomcat startup error 5 132
Java: anonymous class 4 37
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

713 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