use of com.generallycloud.baseio.codec.charbased.CharBasedProtocolFactory in project baseio by generallycloud.
the class TestLineBasedBroadcastServer method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
long old = System.currentTimeMillis();
String res = "hello world!";
future.write(res);
ChannelAcceptor acceptor = (ChannelAcceptor) session.getContext().getChannelService();
acceptor.broadcast(future);
long now = System.currentTimeMillis();
System.out.println("广播花费时间:" + (now - old) + ",连接数:" + session.getContext().getSessionManager().getManagedSessionSize());
}
};
ServerConfiguration configuration = new ServerConfiguration();
configuration.setSERVER_PORT(18300);
configuration.setSERVER_SESSION_IDLE_TIME(180000);
configuration.setSERVER_MEMORY_POOL_CAPACITY(1024 * 512);
configuration.setSERVER_MEMORY_POOL_UNIT(64);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new CharBasedProtocolFactory());
acceptor.bind();
}
use of com.generallycloud.baseio.codec.charbased.CharBasedProtocolFactory in project baseio by generallycloud.
the class TestLineBasedClient 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(18300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new CharBasedProtocolFactory());
SocketSession session = connector.connect();
CharBasedFuture future = new CharBasedFutureImpl(context);
future.write("hello server!");
session.flush(future);
ThreadUtil.sleep(100);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.charbased.CharBasedProtocolFactory in project baseio by generallycloud.
the class TestLineBasedServer method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
String res = "yes server already accept your message:" + future.getReadText();
future.write(res);
session.flush(future);
}
};
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new CharBasedProtocolFactory());
File certificate = FileUtil.readFileByCls("generallycloud.com.crt");
File privateKey = FileUtil.readFileByCls("generallycloud.com.key");
SslContext sslContext = SSLUtil.initServer(privateKey, certificate);
context.setSslContext(sslContext);
acceptor.bind();
}
Aggregations