Solved

Socket-connection from an applets init()

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

11 Experts available now in Live!

Get 1:1 Help Now