BUG: DatagramSocket Causes Security ExceptionID: Q186032
|
Creating a DatagramSocket generates the following exception in your Java console:
NOTE: This exception may also occur on a port other than zero.com.ms.security.SecurityExceptionEx[className.methodName]:
cannot access port 0
The Microsoft virtual machine incorrectly implements creating a DatagramSocket as a trusted network operation. The correct behavior would be to only treat the act of using the DatagramSocket to communicate with a computer other than the computer hosting the applet is a trusted operation.
To workaround this problem, you must make your applet trusted. See the REFERENCES section below for articles explaining how to make your applet trusted.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
// DatagramSocketDemo.java
// ======================
import java.awt.*;
import java.net.*;
public class DatagramSocketDemo extends java.applet.Applet {
Label label=new Label("");
public void init() {
setLayout(new BorderLayout());
add(new Button("Click me to create a Datagram"),"North");
add(label,"Center");
}
public boolean action(Event ev, Object ob) {
try {
DatagramSocket ds=new DatagramSocket(9000);
System.out.println("Succeeded");
label.setText(
"Bug Fixed -- successfully created a DatagramSocket."
);
} catch (SocketException ex) {
ex.printStackTrace();
label.setText("SocketException: "+ex.getMessage());
} catch (com.ms.security.SecurityExceptionEx ex) {
ex.printStackTrace();
label.setText("Bug -- SecurityExceptionEx: "+ex.getMessage());
}
return true;
}
}
<HTML>
<HEAD>
<TITLE>DatagramSocketDemo</TITLE>
</HEAD>
<BODY>
<APPLET CODE=DatagramSocketDemo width=600 height=100>
</APPLET>
<HR>
<A HREF="DatagramSocketDemo.java">The source.</a>
</BODY>
</HTML>
For other information on making your code trusted, please see the Microsoft SDK for Java documentation, available at the following Web site:
http://www.microsoft.com/java/For additional information, please see the following articles in the Microsoft Knowledge Base:
Q181374 INFO: Related Component Download Articles
Q175622 PRB: SecurityExceptionEx Exception Running a Java AppletFor additional information on making your Java Code trusted in Microsoft Internet Explorer, please refer to the following Knowledge Base article:
Q193877 HOWTO: Make your Java Code Trusted in Internet Explorer
© Microsoft Corporation 1998, All Rights Reserved.
Contributions by Derek Jamison, Microsoft Corporation
Additional query words: securityexception datagramsocket kbDSupport kbdsi
Keywords : kbSDKJava200 kbSDKJava201 kbSDKJava300 kbSDKJava310 kbSDKJava202 NetPkg JSecurity
Version : WINDOWS:2.0,2.01,2.02
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: July 28, 1999