1 /*
2  * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License 2.0 which is available at
6  * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7  * which is available at https://www.apache.org/licenses/LICENSE-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10  */
11 
12 module hunt.net.NetClient;
13 
14 import hunt.net.Connection;
15 
16 import hunt.net.codec.Codec;
17 import hunt.net.ClientOptionsBase;
18 import hunt.net.NetClientOptions;
19 
20 /**
21  * A TCP client.
22  * <p>
23  * Multiple connections to different servers can be made using the same instance.
24  * <p>
25  * This client supports a configurable number of connection attempts and a configurable
26  * delay between attempts.
27  *
28  * @author <a href="http://tfox.org">Tim Fox</a>
29  */
30 interface NetClient {
31 
32     /**
33      * Open a connection to a server at the specific {@code port} and {@code host}.
34      * <p>
35      * {@code host} can be a valid host name or IP address. The connect is done asynchronously and on success, a
36      * {@link Connection} instance is supplied via the {@code connectHandler} instance
37      *
38      * @param port  the port
39      * @param host  the host
40      * @return a reference to this, so the API can be used fluently
41      */
42     
43     void connect(string host, int port); 
44 
45     /**
46      * Open a connection to a server at the specific {@code port} and {@code host}.
47      * <p>
48      * {@code host} can be a valid host name or IP address. The connect is done asynchronously and on success, a
49      * {@link Connection} instance is supplied via the {@code connectHandler} instance
50      *
51      * @param port the port
52      * @param host the host
53      * @param serverName the SNI server name
54      * @return a reference to this, so the API can be used fluently
55      */
56     
57     void connect(string host, int port, string serverName); 
58 
59 
60     /**
61      * Close the client.
62      * <p>
63      * Any sockets which have not been closed manually will be closed here. The close is asynchronous and may not
64      * complete until some time after the method has returned.
65      */
66     void close();
67 
68     bool isConnected();
69 
70     int getId();
71     
72     string getHost();
73 
74     int getPort();
75 
76     NetClientOptions getOptions();
77 
78     NetClient setOptions(NetClientOptions options);
79 
80     Codec getCodec();
81 
82     NetClient setCodec(Codec codec);
83 
84     NetConnectionHandler getHandler();
85 
86     NetClient setHandler(NetConnectionHandler handler);
87 
88     // void setOnClosed (void delegate());
89 
90     alias onClosed = setOnClosed;
91     // deprecated("Using onClosed instead.")
92     void setOnClosed (void delegate() handler);
93 }
94