use of com.firenio.codec.lengthvalue.LengthValueCodec in project baseio by generallycloud.
the class TestLengthValueServer method main.
public static void main(String[] args) throws Exception {
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) throws Exception {
String text = f.getStringContent();
f.setContent(ch.allocateWithSkipHeader(1));
f.write("yes server already accept your message:", ch);
f.write(text, ch);
ch.writeAndFlush(f);
}
};
ChannelAcceptor context = new ChannelAcceptor(8300);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.setIoEventHandle(eventHandleAdaptor);
context.addProtocolCodec(new LengthValueCodec());
context.bind();
}
use of com.firenio.codec.lengthvalue.LengthValueCodec in project baseio by generallycloud.
the class TestByteBufPool method main.
public static void main(String[] args) throws Exception {
ChannelConnector context = new ChannelConnector("192.168.1.102", 6500);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new LengthValueCodec());
Channel ch = context.connect(3000);
ByteBuf buf = ch.allocate();
ch.close();
buf.release();
}
use of com.firenio.codec.lengthvalue.LengthValueCodec in project baseio by generallycloud.
the class TestLengthValueBroadcastServer method main.
public static void main(String[] args) throws Exception {
final ChannelManagerListener channelManagerListener = new ChannelManagerListener();
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame frame) throws Exception {
LengthValueFrame f = (LengthValueFrame) frame;
frame.write("yes server already accept your message:", ch);
frame.write(f.getStringContent(), ch);
ch.writeAndFlush(f);
}
};
ChannelAcceptor context = new ChannelAcceptor(8300);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addChannelEventListener(new SetOptionListener());
context.addChannelEventListener(channelManagerListener);
context.setIoEventHandle(eventHandleAdaptor);
context.addProtocolCodec(new LengthValueCodec());
context.bind();
Util.exec(() -> {
for (; ; ) {
Util.sleep(1000);
LengthValueFrame frame = new LengthValueFrame();
frame.setContent("broadcast msg ........".getBytes());
try {
channelManagerListener.broadcast(frame);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of com.firenio.codec.lengthvalue.LengthValueCodec in project baseio by generallycloud.
the class TestLengthValueClient1 method main.
public static void main(String[] args) throws Exception {
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame frame) throws Exception {
LengthValueFrame f = (LengthValueFrame) frame;
System.out.println();
System.out.println("____________________" + f.getStringContent());
System.out.println();
}
};
ChannelConnector context = new ChannelConnector(8300);
context.setIoEventHandle(eventHandleAdaptor);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new LengthValueCodec());
Channel ch = context.connect();
StringBuilder sb = new StringBuilder(1024 * 6);
for (int i = 0; i < 1; i++) {
sb.append("hello!");
}
for (int i = 0; i < 20; i++) {
LengthValueFrame frame = new LengthValueFrame();
frame.write(sb.toString(), ch);
ch.writeAndFlush(frame);
}
Util.sleep(100);
Util.close(context);
}
use of com.firenio.codec.lengthvalue.LengthValueCodec in project baseio by generallycloud.
the class TestReconnectClient method main.
public static void main(String[] args) throws Exception {
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame frame) throws Exception {
}
};
ChannelConnector context = new ChannelConnector(8300);
ReConnector connector = new ReConnector(context);
connector.setRetryTime(5000);
context.setIoEventHandle(eventHandleAdaptor);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new LengthValueCodec());
// context.addChannelEventListener(new CloseConnectorSEListener(connector.getRealConnector()));
connector.connect();
int count = 99999;
for (int i = 0; ; i++) {
Util.sleep(1000);
if (i > count) {
break;
}
}
Util.close(connector);
}
Aggregations