Solved

Socket-connection from an applets init()

Posted on 1998-09-02
4
270 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java - Why doesn't this JFrame work 3 59
tomcat not starting 6 45
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 33
Chrome and Firefox Java 5 32
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

777 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