Why this applet not work ?

Please, someone can tell me why this applet not work ? I already signed it.

I realy need run this applet in IE4 with Microsoft JVM. I know all about the problem with JVM Microsoft but my client only have this platform !

--

import java.applet.Applet;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import com.ms.security.*;

public class Sec extends Applet {

public void init() {

PolicyEngine.assertPermission(PermissionID.NETIO);

byte[] buf = new byte[500];

try {

System.out.println("I will execute datagram socket.");

DatagramSocket ds = new DatagramSocket(6644);

DatagramPacket dp = new DatagramPacket(buf, 500);

ds.receive(dp);

System.err.println("Recebido:" + new String(buf));

} catch (Exception e) {

e.printStackTrace();

}

}

}

When the applet execute i take this message in Java console :

Microsoft (R) VM for Java, 5.0 Release 5.0.0.3805

==============================================

? ajuda

c limpar

f executar finalizadores

g coleta de lixo

m uso de mem髍ia

q fechar

t lista de segmentos

==============================================

I will execute datagram socket.

com.ms.security.SecurityExceptionEx[com/ibm/toolbar/Sec.init]: cannot access 6644

at com/ms/security/permissions/NetIOPermission.check

at com/ms/security/PolicyEngine.deepCheck

at com/ms/security/PolicyEngine.checkPermission

at com/ms/security/StandardSecurityManager.chk

at com/ms/security/StandardSecurityManager.checkListen

at java/net/DatagramSocket.create

at java/net/DatagramSocket.<init>

at java/net/DatagramSocket.<init>

at com/ibm/toolbar/Sec.init

at com/ms/applet/AppletPanel.securedCall0

at com/ms/applet/AppletPanel.securedCall

at com/ms/applet/AppletPanel.processSentEvent

at com/ms/applet/AppletPanel.processSentEvent

at com/ms/applet/AppletPanel.run

at java/lang/Thread.run

com.ms.security.SecurityExceptionEx[com/ibm/toolbar/Sec.init]: cannot access 6644

at java/net/DatagramSocket.CheckCanReceive

at java/net/DatagramSocket.receive

at com/ibm/toolbar/Sec.init

at com/ms/applet/AppletPanel.securedCall0

at com/ms/applet/AppletPanel.securedCall

at com/ms/applet/AppletPanel.processSentEvent

at com/ms/applet/AppletPanel.processSentEvent

at com/ms/applet/AppletPanel.run

at java/lang/Thread.run

com.ms.security.SecurityExceptionEx[com/ibm/toolbar/Sec.init]: cannot access 6644

at java/net/DatagramSocket.CheckCanReceive

at java/net/DatagramSocket.receive

at com/ibm/toolbar/Sec.init

at com/ms/applet/AppletPanel.securedCall0

at com/ms/applet/AppletPanel.securedCall

at com/ms/applet/AppletPanel.processSentEvent

at com/ms/applet/AppletPanel.processSentEvent

at com/ms/applet/AppletPanel.run

at java/lang/Thread.run

Thanks...

[3070 byte] By [jimmycw74a] at [2007-9-29 19:33:23]
# 1

I remove these two lines,

import com.ms.security.*;

PolicyEngine.assertPermission(PermissionID.NETIO);

used `jar cvf Sec.jar Sec.class` and `keytool` and `jarsigner SSec.jar Sec.jar`

make sure

<applet code="Sec.class" archive="SSec.jar" width=500 height=500>

</applet>

wwhite@clellanddata.coma at 2007-7-15 20:52:00 > top of Java-index,Security,Signed Applets...
# 2

MS VM allows only properly signed .CAB files to be executed (JAR's are being neglected).

Just drop it, my suggestion. As a hint: just to put you in the right position to start would take about two A4 pages.

Whatever you are starving for (and cannot use Sun's Plug-In): think of Macromedia Flash. In its latest versions it way overpassed Java as a network/media tool.

SevaK02a at 2007-7-15 20:52:00 > top of Java-index,Security,Signed Applets...
# 3
Sore guys,But they need read all the text i post below. I realy need use MS JVM and the security problem still not resolv.The 2 answer磗 do not end my problem.Thank you, Jimmy
jimmycw74a at 2007-7-15 20:52:00 > top of Java-index,Security,Signed Applets...
# 4

i've been playing with applets and UDP, and have found that I do not need a signed applet :)

The applet will make a connection to the server the applet came from.

Here is sample code,

Sorry I do not know about MS jvm, but this does work with the latest java plugin.

public void start() {

try {

byte[] buffer = new byte[256];

URL url = getDocumentBase();

String host = url.getHost();

Socket socket = new Socket(host, 80);

InetAddress addr = socket.getLocalAddress();

DatagramSocket dsocket = null;

DatagramSocket dsocket1 = null;

DatagramPacket dpacket;

dsocket = new DatagramSocket(22222);

dsocket1 = new DatagramSocket(22223);

dpacket = new DatagramPacket(buffer,buffer.length, InetAddress.getByName("SERVER NAME HERE or IP"),8888); //i used ip

try{

dsocket.send(dpacket);

dsocket1.send(dpacket);

dsocket.receive(dpacket);

dsocket.close();

dsocket1.receive(dpacket);

dsocket1.close();

} catch (IOException ex){

addItem(ex.toString());

}

I ran a simple server code that would just relay packets back to where they came from.

wwhite@clellanddata.coma at 2007-7-15 20:52:00 > top of Java-index,Security,Signed Applets...
# 5
Hi , I am also facing the same issue with the MSJVM environment.Even after i signed my cab file, it still throws the following exception;com.ms.security.SecurityExceptionEx[Host]: cannot connect to "Some IP".Any guess?
pragalathar@yahoo.co.ina at 2007-7-15 20:52:00 > top of Java-index,Security,Signed Applets...
# 6

Hi Jim,

I got the solution for the problem in the MSJVM environment. The fix is:

Regarding com.ms.security.SecurityExceptionEx you may find more information at the following link:

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q175/6/22.asp&NoWebContent=1

The exception may occur if an applet tries to do some forbidden action in

one of following places:

- default constructor, init(), start(), stop() or destroy() method. Proposed

work around is " start a thread and write the critical code in its run() method:"

So your code becomes;

import java.applet.Applet;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import com.ms.security.*;

public class Sec extends Applet {

public void init() {

Thread providerThread = new Thread(){

public void run(){

myFunction();

}

};

providerThread.start();

try {

providerThread.join();

} catch (InterruptedException e) {

e.printStackTrace();

System.exit(-1);

}

}

private void myFunction() {

PolicyEngine.assertPermission(PermissionID.NETIO);

byte[] buf = new byte[500];

try {

System.out.println("I will execute datagram socket.");

DatagramSocket ds = new DatagramSocket(6644);

DatagramPacket dp = new DatagramPacket(buf, 500);

ds.receive(dp);

System.err.println("Recebido:" + new String(buf));

} catch (Exception e) {

e.printStackTrace();

}

}

}

Surely this will work:)

Thanks

Arun Govindan

pragalathar@yahoo.co.ina at 2007-7-15 20:52:00 > top of Java-index,Security,Signed Applets...
# 7

Hello !

I followed your example and I tried the code below, but is not working. It gives the following exception :

Exception: com.ms.security.SecurityExceptionEx[Win32Cim_Threaded.myFunction]

Could you please advice me ?

Thank you in advance.

import java.sql.Connection;

//package WmiQueryInterface;

import com.ms.activeX.ActiveXComponent;

import com.ms.com.Dispatch;

import com.ms.com.Variant;

import java.applet.*;

import java.awt.*;

/**

* @author SPetit

*

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

public class Win32Cim_Threaded extends Applet {

public static String text;

public void init() {

Thread providerThread = new Thread(){

public void run(){

myFunction();

}

};

providerThread.start();

try {

providerThread.join();

} catch (InterruptedException e) {

e.printStackTrace();

System.exit(-1);

}

}

private void myFunction() {

try {

ActiveXComponent wmi = new ActiveXComponent ("WbemScripting.SWbemLocator");

//ActiveXComponent wmi = new ActiveXComponent("winmgmts:{impersonationLevel=impersonate}!\\\\127.0.0.1\\root\\cimv2");

text = "1234";

//this.showStatus("aaa");

//Object query = wmi.getObject();

//Object test = Dispatch.call(query,"ExecQuery","Select * From win32_process");

//Variant variant = new Variant(false);

//variant = Dispatch.get(test,"name");

//String text = variant.getString();

//this.showStatus(text);

//this.showStatus("aaa");

//new Win32Cim().paint1(g);

//System.out.println(variant);

}

catch (Exception e) {

System.out.println("Exception: "+e);

//this.showStatus("Exception: "+e);

}

}

}

ovidiustefa at 2007-7-15 20:52:00 > top of Java-index,Security,Signed Applets...