use of com.firenio.codec.lengthvalue.LengthValueFrame in project baseio by generallycloud.
the class TestHeartBeat 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 LengthValueCodec());
context.setIoEventHandle(eventHandleAdaptor);
Channel ch = context.connect();
String param = "tttt";
long old = Util.now();
for (int i = 0; i < 5; i++) {
Frame frame = new LengthValueFrame();
frame.setString(param, ch);
ch.writeAndFlush(frame);
Util.sleep(300);
}
System.out.println("Time:" + (Util.past(old)));
Thread.sleep(2000);
Util.close(context);
}
use of com.firenio.codec.lengthvalue.LengthValueFrame in project baseio by generallycloud.
the class TestLengthValueClient method main.
public static void main(String[] args) throws Exception {
ChannelConnector context = new ChannelConnector("127.0.0.1", 8300);
IoEventHandle eventHandle = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) throws Exception {
System.out.println();
System.out.println("____________________" + f.getStringContent());
System.out.println();
context.close();
}
};
context.setIoEventHandle(eventHandle);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new LengthValueCodec());
Channel ch = context.connect(3000);
LengthValueFrame frame = new LengthValueFrame();
frame.setString("hello server!", ch);
ch.writeAndFlush(frame);
}
use of com.firenio.codec.lengthvalue.LengthValueFrame in project baseio by generallycloud.
the class TestLengthValueServerJunit method testClientAsync.
public void testClientAsync() throws Exception {
Waiter<String> w = new Waiter<>();
ChannelConnector context = new ChannelConnector(8300);
IoEventHandle eventHandle = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) throws Exception {
System.out.println();
System.out.println("____________________" + f.getStringContent());
System.out.println();
context.close();
w.call(f.getStringContent(), null);
}
};
context.setIoEventHandle(eventHandle);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new LengthValueCodec());
context.connect((ch, ex) -> {
LengthValueFrame f = new LengthValueFrame();
f.setString(hello, ch);
try {
ch.writeAndFlush(f);
} catch (Exception e) {
e.printStackTrace();
}
});
w.await(1000);
v(w.getResponse());
}
use of com.firenio.codec.lengthvalue.LengthValueFrame in project baseio by generallycloud.
the class TestLengthValueServerJunit method testClient.
public void testClient() throws Exception {
Waiter<String> w = new Waiter<>();
ChannelConnector context = new ChannelConnector(8300);
IoEventHandle eventHandle = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) throws Exception {
System.out.println();
System.out.println("____________________" + f.getStringContent());
System.out.println();
context.close();
w.call(f.getStringContent(), null);
}
};
context.setIoEventHandle(eventHandle);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addProtocolCodec(new LengthValueCodec());
Channel ch = context.connect();
LengthValueFrame f = new LengthValueFrame();
f.setString(hello, ch);
ch.writeAndFlush(f);
w.await(1000);
v(w.getResponse());
}
Aggregations