这两个链接都提供了非常有用的信息,所以谢谢你们。因为此服务器不会等待来自任何其他客户端的连接
WebView
Task
它在后台运行,也可以传递给
ExecutorService
.
private void startServerToSpawnPty() {
Task<Void> serverTask = new Task<Void>( ) {
@Override
protected Void call() throws Exception {
ServerSocket server = new ServerSocket(8080);
System.out.println("Created Java localhost server on port: 8080");
final Socket client = server.accept( );
if (client.isConnected( )) {
System.out.println("client connected: " + client.isConnected( ));
System.out.println("You just connected with the Java localhost" +
"server on port: 8080");
} else
System.out.println("No connection found");
return null;
}
};
ExecutorService service = Executors.newFixedThreadPool(1);
service.execute(serverTask);
service.shutdown();
}