Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use DatagramSocket with an Applet?

Status
Not open for further replies.

davidchardonnet

Programmer
Mar 21, 2001
167
FR
Hello
I coded a java server application and a java client application using DatagramSocket and it works very well, and each application can send and receive information from the other application.
Now I tried to migrate the client application into an applet and now, the navigator raises an exception:
com.ms.security.SecurityExceptionEx(ClientApplet.connect): cannot access 5000
where 5000 is the port number on which the server is listening.
Can anybody help me?

Thank you very much
David
 
The security restrictions on applets are pretty extreme now, as far as I know aplets are not allowed to open connections to remote machines or to do any file reading off the host machine, in the same way appln's are. If I am wrong, someone please let me know, I have a project right now that could benefit. You may want to look into Remote Method Invocation, a set of classes in java that allow you to remotely connect back a class running on the server. That class on the server is accessed by function calls, and it is treated as a machine resident program rather than applet, thus allowing the server-side class to do whatever it pleases than transmitting whatever data you need back to the client. (java.rmi)
 
Hi,

Are you planning to run the applet locally or over the Internet?? If locally, did you "adjust" the security rights for applets??

I did an Applet using UDP as well. However, I started off coding the program as an Applet, not as an application. So maybe if changing the access rights still doesn't work then maybe there are some parts of the program that you missed out on?? because everything works fine for the program that I created.

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
I intend to use this applet on the internet, but right now I am testing it on a LAN, the server runs on a distant machine and the applet runs on a client browser on another machine. The browser gets the applet by a web page that is on the distant machine where the server application runs.

But how can you adjust security rights for applets?

Thank you for your help.

David
 
Hi,

One important thing. Are you going to access the client's pc at all?? For example, accessing and printing to the default printer on a client's pc. If yes, you would have to get your applet signed before you can implement it on the internet.

For testing purposes, you can edit the settings of the java.policy file from :

// Standard extensions get all permissions by default

grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};

// default permissions granted to all domains

grant {

// Allows any thread to stop itself using the java.lang.Thread.stop()
...

To :


// Standard extensions get all permissions by default

grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};

// default permissions granted to all domains

grant {

grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};

// Allows any thread to stop itself using the java.lang.Thread.stop()
...

Please take note that I used 'permission java.security.AllPermission'. This isn't the correct way of setting permissions. It just save the trouble of having to grant permission to all the appropriate stuff. But it should be alright for testing purposes

The 2 java.policy file would be found in the 2 folders:
c:\program files\javasoft\JRE\1.3\lib\security
c:\jdk1.3\jre\lib\security

Hope this helps.
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top