use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.
the class HelloWorldCommand method start.
@Override
public void start() throws Exception {
Command helloWorld = CommandBuilder.command("hello-world").processHandler(process -> {
process.write("hello world\n");
process.end();
}).build(vertx);
ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
CommandRegistry.getShared(vertx).registerCommand(helloWorld);
service.start(ar -> {
if (!ar.succeeded()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.
the class WgetCommand method start.
@Override
public void start() throws Exception {
// Create the wget CLI
CLI cli = CLI.create("wget").setSummary("Wget implemented with Vert.x HTTP client").addArgument(new Argument().setIndex(0).setArgName("http-url").setDescription("the HTTP uri to get"));
// Create the command
Command helloWorld = CommandBuilder.command(cli).processHandler(process -> {
URL url;
try {
url = new URL(process.commandLine().getArgumentValue(0));
} catch (MalformedURLException e) {
process.write("Bad url\n").end();
return;
}
HttpClient client = process.vertx().createHttpClient();
process.write("Connecting to " + url + "\n");
int port = url.getPort();
if (port == -1) {
port = 80;
}
HttpClientRequest req = client.get(port, url.getHost(), url.getPath());
req.exceptionHandler(err -> {
process.write("wget: error " + err.getMessage() + "\n");
process.end();
});
req.handler(resp -> {
process.write(resp.statusCode() + " " + resp.statusMessage() + "\n");
String contentType = resp.getHeader("Content-Type");
String contentLength = resp.getHeader("Content-Length");
process.write("Length: " + (contentLength != null ? contentLength : "unspecified"));
if (contentType != null) {
process.write("[" + contentType + "]");
}
process.write("\n");
process.end();
});
req.end();
}).build(vertx);
ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
CommandRegistry.getShared(vertx).registerCommand(helloWorld);
service.start(ar -> {
if (!ar.succeeded()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.
the class TermCast method start.
@Override
public void start(Future<Void> startFuture) throws Exception {
termServer = TermServer.createTelnetTermServer(vertx, new TelnetTermOptions().setHost("localhost").setPort(3000).setInBinary(false));
Robot robot = new Robot();
termServer.termHandler(term -> {
new ScreenCaster(vertx, robot, term).handle();
});
termServer.listen(ar -> {
if (ar.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(ar.cause());
}
});
}
Aggregations