use of com.generallycloud.baseio.connector.SocketChannelConnector 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.connector.SocketChannelConnector 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();
}
use of com.generallycloud.baseio.connector.SocketChannelConnector in project baseio by generallycloud.
the class TestSubscribe method test.
private static void test() 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 ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
MessageConsumer consumer = new DefaultMessageConsumer(session);
consumer.subscribe(new OnMessage() {
@Override
public void onReceive(Message message) {
System.out.println(message);
}
});
connector.close();
}
use of com.generallycloud.baseio.connector.SocketChannelConnector in project baseio by generallycloud.
the class TestTeller method main.
public static void main(String[] args) throws Exception {
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(8300));
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ParamedProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
boolean b = session.login("admin", "admin100");
System.out.println(b);
MessageProducer producer = new DefaultMessageProducer(session);
TextMessage message = new TextMessage("msgId", "uuid", "你好!");
MapMessage mapMessage = new MapMessage("msgId", "uuid");
mapMessage.put("test", "test111111111111111111111");
long old = System.currentTimeMillis();
producer.offer(message);
producer.offer(mapMessage);
System.out.println("Time:" + (System.currentTimeMillis() - old));
connector.close();
}
use of com.generallycloud.baseio.connector.SocketChannelConnector in project baseio by generallycloud.
the class TestStopServer 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 ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
ProtobaseFuture future = session.request("test-stop-server2.auth", null);
System.out.println(future.getReadText());
CloseUtil.close(connector);
}
Aggregations