use of com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture in project baseio by generallycloud.
the class TestFIxedLengthClient 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();
}
};
SslContext sslContext = SSLUtil.initClient(true);
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration("localhost", 18300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
// context.addSessionEventListener(new SessionActiveSEListener());
context.setBeatFutureFactory(new FLBeatFutureFactory());
context.setProtocolFactory(new FixedLengthProtocolFactory());
context.setSslContext(sslContext);
SocketSession session = connector.connect();
FixedLengthFuture future = new FixedLengthFutureImpl(context);
future.write("hello server!");
session.flush(future);
ThreadUtil.sleep(100);
CloseUtil.close(connector);
DebugUtil.debug("连接已关闭。。。");
}
use of com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture in project baseio by generallycloud.
the class TestLoadServer method main.
public static void main(String[] args) throws Exception {
LoggerFactory.configure();
final AtomicInteger res = new AtomicInteger();
final AtomicInteger req = new AtomicInteger();
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
FixedLengthFuture f = (FixedLengthFuture) future;
String res = "yes server already accept your message" + f.getReadText();
f.write(res);
session.flush(future);
// System.out.println("req======================"+req.getAndIncrement());
}
};
ServerConfiguration c = new ServerConfiguration(8300);
c.setSERVER_MEMORY_POOL_CAPACITY(2560000);
c.setSERVER_MEMORY_POOL_UNIT(128);
c.setSERVER_MEMORY_POOL_CAPACITY_RATE(0.5);
c.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
c.setSERVER_CORE_SIZE(6);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.setProtocolFactory(new FixedLengthProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
// context.addSessionEventListener(new SetOptionListener());
acceptor.bind();
}
use of com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture in project baseio by generallycloud.
the class SimpleTestFIxedLengthBroadcastServer method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
future.write("yes server already accept your message:");
future.write(future.getReadText());
session.flush(future);
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(8300));
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.addSessionEventListener(new LoggerSocketSEListener());
context.addSessionEventListener(new SetOptionListener());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new FixedLengthProtocolFactory());
acceptor.bind();
ThreadUtil.execute(new Runnable() {
@Override
public void run() {
for (; ; ) {
ThreadUtil.sleep(1000);
FixedLengthFuture future = new FixedLengthFutureImpl(context);
future.write("broadcast msg .........................");
try {
acceptor.broadcast(future);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
use of com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture in project baseio by generallycloud.
the class SimpleTestFIxedLengthClient 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("localhost", 8300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new FixedLengthProtocolFactory());
SocketSession session = connector.connect();
FixedLengthFuture future = new FixedLengthFutureImpl(context);
future.write("hello server!");
session.flush(future);
ThreadUtil.sleep(100);
CloseUtil.close(connector);
}
Aggregations