use of com.generallycloud.baseio.component.NioSocketChannelContext 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.component.NioSocketChannelContext 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.component.NioSocketChannelContext 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.component.NioSocketChannelContext 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);
}
use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestUpload method main.
public static void main(String[] args) throws Exception {
String serviceName = "/test-upload";
IoEventHandleAdaptor eventHandle = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
ProtobaseFuture f = (ProtobaseFuture) future;
System.out.println();
System.out.println(f.getReadText());
System.out.println();
CloseUtil.close(connector);
}
};
LoggerFactory.configure();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
SocketSession session = connector.connect();
String fileName = "lantern-installer-beta.exe";
fileName = "content.rar";
// fileName = "jdk-8u102-windows-x64.exe";
File file = new File("c:/ryms/" + fileName);
FileSendUtil fileSendUtil = new FileSendUtil();
fileSendUtil.sendFile(session, serviceName, file, 1024 * 800);
ThreadUtil.sleep(10000000);
}
Aggregations