use of com.generallycloud.baseio.component.LoggerSocketSEListener 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.component.LoggerSocketSEListener 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();
}
use of com.generallycloud.baseio.component.LoggerSocketSEListener 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.component.LoggerSocketSEListener 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);
}
use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.
the class TestPublish method main.
public static void main(String[] args) throws Exception {
LoggerFactory.configure();
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ParamedProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
MessageProducer producer = new DefaultMessageProducer(session);
TextMessage message = new TextMessage("msgId", "qName", "你好!");
producer.publish(message);
connector.close();
}
Aggregations