-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathjava-channel-AsynchronousSocketChannel.java
More file actions
69 lines (56 loc) · 2.36 KB
/
java-channel-AsynchronousSocketChannel.java
File metadata and controls
69 lines (56 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-----------------------------------
AsynchronousServerSocketChannel |
-----------------------------------
# 异步,非阻塞客户端Socket通道
-----------------------------------
AsynchronousServerSocketChannel-API|
-----------------------------------
# 静态方法
AsynchronousSocketChannel open(AsynchronousChannelGroup group);
* 打开一个异步通道,使用指定的 ChannelGroup
AsynchronousSocketChannel open();
* 打开一个异步通道
# 实例方法
//==========================绑定
AsynchronousSocketChannel bind(SocketAddress local);
* 绑定本机地址
//==========================连接
Future<Void> connect(SocketAddress remote);
* 连接远程服务器
* demo
asynchronousSocketChannel.connect(new InetSocketAddress("localhost",55));
<A> void connect(SocketAddress remote,A attachment,CompletionHandler<Void,? super A> handler);
* 连接远程主机
//==========================读取
Future<Integer> read(ByteBuffer dst);
<A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler);
<A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer,? super A> handler)
<A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
//==========================写入
Future<Integer> write(ByteBuffer src)
<A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)
<A> void write(ByteBuffer src, A attachment, CompletionHandler<Integer,? super A> handler)
<A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)\
//=========================配置
<T> AsynchronousSocketChannel setOption(SocketOption<T> name, T value);
* 设置配置
<T> T getOption(SocketOption<T> name);
* 获取配置
Set<SocketOption<?>> supportedOptions();
* 获取支持的配置
//=========================关闭
AsynchronousSocketChannel shutdownInput()
* 关闭读,并没有关闭连接
AsynchronousSocketChannel shutdownOutput()
* 关闭写,并没有关闭连接
void close();
* 关闭连接
//==========================其他
boolean isOpen();
* 连接是否打开
SocketAddress getLocalAddress();
* 本地地址
SocketAddress getRemoteAddress()
* 远程地址
AsynchronousChannelProvider provider()
* 未知