mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add ChannelUtil
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
package cn.hutool.socket.aio;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.thread.ThreadFactoryBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.AsynchronousChannelGroup;
|
||||
|
||||
public class AioClientTest {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
final AsynchronousChannelGroup GROUP = AsynchronousChannelGroup.withFixedThreadPool(//
|
||||
Runtime.getRuntime().availableProcessors(), // 默认线程池大小
|
||||
ThreadFactoryBuilder.create().setNamePrefix("Huool-socket-").build()//
|
||||
);
|
||||
|
||||
AioClient client = new AioClient(new InetSocketAddress("localhost", 8899), new SimpleIoAction() {
|
||||
|
||||
|
||||
@Override
|
||||
public void doAction(AioSession session, ByteBuffer data) {
|
||||
if(data.hasRemaining()) {
|
||||
@@ -19,10 +27,10 @@ public class AioClientTest {
|
||||
Console.log("OK");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
client.write(ByteBuffer.wrap("Hello".getBytes()));
|
||||
client.read();
|
||||
|
||||
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user