mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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")//
|
||||
|
@@ -47,4 +47,4 @@ public class NioClientTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -47,4 +47,4 @@ public class NioServerTest {
|
||||
//将缓冲数据写入渠道,返回给客户端
|
||||
channel.write(BufferUtil.createUtf8(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user