use of com.generallycloud.baseio.codec.charbased.future.CharBasedFuture in project baseio by generallycloud.
the class CharBasedProtocolEncoder method encode.
@Override
public void encode(SocketChannel channel, ChannelFuture future) throws IOException {
ByteBufAllocator allocator = channel.getByteBufAllocator();
CharBasedFuture f = (CharBasedFuture) future;
int writeSize = f.getWriteSize();
if (writeSize == 0) {
throw new IOException("null write buffer");
}
ByteBuf buf = allocator.allocate(writeSize + 1);
buf.put(f.getWriteBuffer(), 0, writeSize);
buf.putByte(splitor);
future.setByteBuf(buf.flip());
}
use of com.generallycloud.baseio.codec.charbased.future.CharBasedFuture in project baseio by generallycloud.
the class TestLineBasedClient method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
System.out.println();
System.out.println("____________________" + future.getReadText());
System.out.println();
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new CharBasedProtocolFactory());
SocketSession session = connector.connect();
CharBasedFuture future = new CharBasedFutureImpl(context);
future.write("hello server!");
session.flush(future);
ThreadUtil.sleep(100);
CloseUtil.close(connector);
}
Aggregations