This commit is contained in:
Looly
2022-04-28 03:20:23 +08:00
parent 17cd183722
commit 8e2c06c671
96 changed files with 175 additions and 167 deletions

View File

@@ -9,7 +9,7 @@ import java.nio.ByteBuffer;
public class AioClientTest {
public static void main(String[] args) {
AioClient client = new AioClient(new InetSocketAddress("localhost", 8899), new SimpleIoAction() {
@Override
public void doAction(AioSession session, ByteBuffer data) {
if(data.hasRemaining()) {
@@ -19,10 +19,10 @@ public class AioClientTest {
Console.log("OK");
}
});
client.write(ByteBuffer.wrap("Hello".getBytes()));
client.read();
client.close();
}
}

View File

@@ -9,23 +9,23 @@ import cn.hutool.log.StaticLog;
import java.nio.ByteBuffer;
public class AioServerTest {
public static void main(String[] args) {
@SuppressWarnings("resource")
AioServer aioServer = new AioServer(8899);
aioServer.setIoAction(new SimpleIoAction() {
@Override
public void accept(AioSession session) {
StaticLog.debug("【客户端】:{} 连接。", session.getRemoteAddress());
session.write(BufferUtil.createUtf8("=== Welcome to Hutool socket server. ==="));
}
@Override
public void doAction(AioSession session, ByteBuffer data) {
Console.log(data);
if(false == data.hasRemaining()) {
StringBuilder response = StrUtil.builder()//
.append("HTTP/1.1 200 OK\r\n")//

View File

@@ -47,4 +47,4 @@ public class NioClientTest {
}
}
}
}
}

View File

@@ -47,4 +47,4 @@ public class NioServerTest {
//将缓冲数据写入渠道,返回给客户端
channel.write(BufferUtil.createUtf8(response));
}
}
}