Eclipse插件服务器拒绝客户端连接

时间:2016-06-17 10:09:49

标签: eclipse-plugin eclipse-rcp

我正在开发一个eclipse插件,它在localhost上创建一个服务器,并且应该接受客户端连接。服务器已成功启动但它拒绝客户端连接。当我打包为Runnable外部jar并作为单独的进程启动时,相同的服务器工作正常并接受客户端连接。我不明白为什么它会在插件系统内启动时拒绝。有没有我不知道的安全设置?请指教。

有效的代码:

Bundle bundle = Platform.getBundle("Resources-Module");
            URL chromeDriverURL = bundle.getEntry("/lib/java-io.server.jar");

            File javaServerJar = null;
            try {
                URL resolvedFileURL = FileLocator.toFileURL(chromeDriverURL);
                URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null);
                javaServerJar = new File(resolvedURI);
                javaServerJar.setExecutable(true);
            } catch (URISyntaxException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }

            ProcessBuilder ps = new ProcessBuilder("java.exe", "-jar",
                    javaServerJar.getAbsolutePath());
            ps.redirectErrorStream(true);
            final Process pr = ps.start();

不起作用的代码(拒绝客户端连接):

Configuration config = new Configuration();
        config.setHostname("localhost");
        config.setPort(3700);
        final SocketIOServer server = new SocketIOServer(config);
        server.addConnectListener(new ConnectListener() {
            public void onConnect(SocketIOClient client) {
                System.out.println("onConnected");
                //This is never printed
            }
        });
        server.addDisconnectListener(new DisconnectListener() {
            public void onDisconnect(SocketIOClient client) {
                System.out.println("onDisconnected");
            }
        });
        server.addEventListener("send", Message.class, new DataListener<Message>() {

            public void onData(SocketIOClient client, Message data, AckRequest ackSender) throws Exception {

            }
        });
        System.out.println("Starting server...");
        server.start();
        System.out.println("Server started");
// This is printed

服务器代码取自:

https://github.com/mrniko/netty-socketio/blob/master/src/main/java/com/corundumstudio/socketio/SocketIOServer.java

0 个答案:

没有答案