use of com.firenio.codec.protobase.ProtobaseFrame in project baseio by generallycloud.
the class TestProtobase method testBinary.
public void testBinary() throws Exception {
Waiter<String> w = new Waiter<>();
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) {
String text = new String(f.getBytesContent(), ch.getCharset());
System.out.println();
System.out.println("____________________" + text);
System.out.println();
Util.close(ch);
w.call(text, null);
}
};
ChannelConnector context = new ChannelConnector(8300);
context.setIoEventHandle(eventHandleAdaptor);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new ProtobaseCodec());
Channel ch = context.connect();
ProtobaseFrame f = new ProtobaseFrame();
f.setBinary();
f.setString(hello, ch);
ch.writeAndFlush(f);
w.await(3000);
Assert.assertEquals(w.getResponse(), res + hello);
}
use of com.firenio.codec.protobase.ProtobaseFrame in project baseio by generallycloud.
the class TestProtobase method testText.
public void testText() throws Exception {
Waiter<String> w = new Waiter<>();
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame frame) {
String text = frame.getStringContent();
System.out.println();
System.out.println("____________________" + text);
System.out.println();
Util.close(ch);
w.call(text, null);
}
};
ChannelConnector context = new ChannelConnector(8300);
context.setIoEventHandle(eventHandleAdaptor);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new ProtobaseCodec());
Channel ch = context.connect();
ProtobaseFrame f = new ProtobaseFrame();
f.setString(hello, ch);
ch.writeAndFlush(f);
w.await(3000);
Assert.assertEquals(w.getResponse(), res + hello);
}
use of com.firenio.codec.protobase.ProtobaseFrame in project baseio by generallycloud.
the class TestProtobaseHeartBeat method main.
public static void main(String[] args) throws Exception {
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame frame) throws Exception {
DebugUtil.debug("______________" + frame);
}
};
NioEventLoopGroup group = new NioEventLoopGroup();
group.setIdleTime(20);
ChannelConnector context = new ChannelConnector(group, "127.0.0.1", 8300);
context.addChannelIdleEventListener(new ChannelActiveListener());
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new ProtobaseCodec());
context.setIoEventHandle(eventHandleAdaptor);
Channel ch = context.connect();
String param = "tttt";
long old = Util.now_f();
for (int i = 0; i < 5; i++) {
Frame f = new ProtobaseFrame();
f.setString(param, ch);
ch.writeAndFlush(f);
Util.sleep(300);
}
System.out.println("Time:" + (Util.past(old)));
Thread.sleep(2000);
Util.close(context);
}
Aggregations