0

我在小程序中使用 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;
            }
         }
    );

请教,我该如何解决?

4

1 回答 1

1

我能够解决这个问题。

首先,我尝试连接到127.0.0.1,但为此我必须安装 Jetty 并将我的 applet 和 hmtl 放入 jetty。所以它开始只适用于本地主机。

与未签名 Java 小程序的原始服务器的套接字连接

10.xyz还是不行,所以我只好签小程序

是否可以免费签署 java 小程序?

也可以crossdomain.xml像这里一样在码头创建:

访问被拒绝(java.net.SocketPermission 127.0.0.1:8080 连接,解决)

于 2013-01-08T11:07:41.570 回答