/*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.vertx.core.net;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.metrics.Measured;
/**
* A TCP client.
* <p>
* Multiple connections to different servers can be made using the same instance.
* <p>
* This client supports a configurable number of connection attempts and a configurable
* delay between attempts.
*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
@VertxGen
public interface NetClient extends Measured {
/**
* Open a connection to a server at the specific {@code port} and {@code host}.
* <p>
* {@code host} can be a valid host name or IP address. The connect is done asynchronously and on success, a
* {@link NetSocket} instance is supplied via the {@code connectHandler} instance
*
* @param port the port
* @param host the host
* @return a reference to this, so the API can be used fluently
*/
@Fluent
NetClient connect(int port, String host, Handler<AsyncResult<NetSocket>> connectHandler);
/**
* Open a connection to a server at the specific {@code port} and {@code host}.
* <p>
* {@code host} can be a valid host name or IP address. The connect is done asynchronously and on success, a
* {@link NetSocket} instance is supplied via the {@code connectHandler} instance
*
* @param port the port
* @param host the host
* @param serverName the SNI server name
* @return a reference to this, so the API can be used fluently
*/
@Fluent
NetClient connect(int port, String host, String serverName, Handler<AsyncResult<NetSocket>> connectHandler);
/**
* Close the client.
* <p>
* Any sockets which have not been closed manually will be closed here. The close is asynchronous and may not
* complete until some time after the method has returned.
*/
void close();
}