mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
29 lines
667 B
Java
Executable File
29 lines
667 B
Java
Executable File
package cn.hutool.socket.aio;
|
|
|
|
import cn.hutool.core.lang.Console;
|
|
import cn.hutool.core.text.StrUtil;
|
|
|
|
import java.net.InetSocketAddress;
|
|
import java.nio.ByteBuffer;
|
|
|
|
public class AioClientTest {
|
|
public static void main(final String[] args) {
|
|
final AioClient client = new AioClient(new InetSocketAddress("localhost", 8899), new SimpleIoAction() {
|
|
|
|
@Override
|
|
public void doAction(final AioSession session, final ByteBuffer data) {
|
|
if(data.hasRemaining()) {
|
|
Console.log(StrUtil.utf8Str(data));
|
|
session.read();
|
|
}
|
|
Console.log("OK");
|
|
}
|
|
});
|
|
|
|
client.write(ByteBuffer.wrap("Hello".getBytes()));
|
|
client.read();
|
|
|
|
client.close();
|
|
}
|
|
}
|