我在applet中使用netty 3,当我从浏览器启动它时,它在Java控制台中提供了以下堆栈跟踪,如果我从Eclipse Applet Viewer运行,那么这个问题就不会发生:
network: Cache entry not found [url: http://<IP address>/crossdomain.xml, version: null]
network: Connecting http://<IP address>/crossdomain.xml with proxy=DIRECT
network: Connecting http://<IP address>:80/ with proxy=DIRECT
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at com.sun.deploy.net.CrossDomainXML$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.deploy.net.CrossDomainXML.privilegedConnect(Unknown Source)
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:150)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:113)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendDownstream(DefaultChannelPipeline.java:771)
at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
at org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:591)
at org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:582)
at org.jboss.netty.channel.Channels.connect(Channels.java:541)
at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:210)
at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
at org.mypackage.Myclass.connect(Client.java:80)
还有这个
Exception caught: [id: 0x00498342] EXCEPTION: java.security.AccessControlException: access denied ("java.net.SocketPermission" "<IP address>:18090" "connect,resolve")
Exception caught: [id: 0x00498342] EXCEPTION: java.nio.channels.ClosedChannelException
我在本地PC上测试但指定了要连接的IP地址。
这是我的连接方法中的第80行:
future = bootstrap.connect(new InetSocketAddress(host, port));
我试图将其包围但没有成功
AccessController.doPrivileged(
new PrivilegedAction<Void>() {
public Void run () {
MyClass.connect(type, userId, secondValue);
return null;
}
}
);
请,建议我该如何解决?
答案 0 :(得分:1)
我能够解决问题。
首先,我尝试连接到127.0.0.1
,但为此我必须安装Jetty并将我的applet和hmtl放在jetty中。所以它开始只适用于localhost。
Socket connection to originating server of an unsigned Java applet
它仍然不适用于10.x.y.z,所以我必须签署applet
Is it possible to sign a java applet for free?
还可以像在这里一样在码头创建crossdomain.xml
:
access denied (java.net.SocketPermission 127.0.0.1:8080 connect,resolve)