use of com.firenio.component.Frame 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.component.Frame 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.component.Frame in project baseio by generallycloud.
the class TestHttpLoadServer method main.
public static void main(String[] args) throws Exception {
IoEventHandle eventHandle = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame frame) throws Exception {
HttpFrame f = (HttpFrame) frame;
f.setConnection(HttpConnection.KEEP_ALIVE);
f.setContentType(HttpContentType.text_plain);
f.setString("Hello World", ch);
ch.writeAndFlush(f);
ch.release(f);
}
};
NioEventLoopGroup group = new NioEventLoopGroup();
group.setMemoryCapacity(1024 * 1024 * 64);
group.setMemoryUnit(512);
group.setEventLoopSize(2);
ChannelAcceptor context = new ChannelAcceptor(group, 8080);
context.addProtocolCodec(new HttpCodec(8));
context.addProtocolCodec(new WebSocketCodec());
context.setIoEventHandle(eventHandle);
context.addChannelEventListener(new LoggerChannelOpenListener());
context.bind();
}
use of com.firenio.component.Frame in project baseio by generallycloud.
the class TestLoadClient1 method run.
@Override
public void run() {
int time1 = getTime();
Channel ch = context.getChannel();
try {
for (int i = 0; i < time1; i++) {
Frame frame = new LengthValueFrame();
frame.setContent(ch.allocateWithSkipHeader(1));
if (debug) {
byte[] bb = new byte[4];
ByteUtil.putInt(bb, i, 0);
frame.write(bb);
}
frame.write(req);
if (debug) {
frame.write(String.valueOf(i).getBytes());
}
ch.writeAndFlush(frame);
if (debug) {
count.incrementAndGet();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.firenio.component.Frame 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);
}
Aggregations