📄 _socketchannel.java
字号:
package org.pool;import java.io.IOException;import java.net.InetSocketAddress;import java.net.Socket;import java.net.SocketAddress;import java.nio.ByteBuffer;import java.nio.channels.SocketChannel;import java.nio.channels.spi.SelectorProvider;public class _SocketChannel { /** * 连接状态 */ private boolean status = true; public SocketChannel socketChannel; public _SocketChannel(InetSocketAddress inetSocketAddress) throws IOException { socketChannel = SocketChannel.open(); socketChannel.configureBlocking(false); socketChannel.connect(inetSocketAddress); } /** * 判断此连接是否空闲 * * @return boolean 空闲返回ture,否则false */ public boolean isFree() { return status; } /** * 当使用此连接的时候设置状态为false(忙碌) */ public void setBusy() { this.status = false; } /** * 当客户端关闭连接的时候状态设置为true(空闲) */ public void close() { System.out.println("Close : set the status is free "); status = true; } public void destroy() { // Close socket connection close(); // System.out.println(Close success ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -