use of com.generallycloud.baseio.codec.http11.future.ClientHttpFuture in project baseio by generallycloud.
the class TestHttpLoadClient method run.
@Override
public void run() {
int time = getTime();
for (int i = 0; i < time; i++) {
HttpFuture future = new ClientHttpFuture(session.getContext(), "/test");
session.flush(future);
}
}
use of com.generallycloud.baseio.codec.http11.future.ClientHttpFuture in project baseio by generallycloud.
the class TestSimpleHttpClient2 method main.
public static void main(String[] args) throws IOException {
String host = "www.baidu.com";
host = "generallycloud.com";
host = "127.0.0.1";
int port = 443;
port = 8080;
HttpIOEventHandle eventHandleAdaptor = new HttpIOEventHandle();
ServerConfiguration c = new ServerConfiguration(host, port);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setProtocolFactory(new ClientHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
if (port == 443) {
context.setSslContext(SSLUtil.initClient(true));
}
SocketSession session = connector.connect();
HttpClient client = new HttpClient(session);
HttpFuture future = new ClientHttpFuture(context, "/");
HttpFuture res = client.request(future, 99990000);
System.out.println();
System.out.println(new String(res.getBodyContent()));
System.out.println();
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.http11.future.ClientHttpFuture in project baseio by generallycloud.
the class TestSimpleWebSocketClient method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
if (future instanceof ClientHttpFuture) {
ClientHttpFuture f = (ClientHttpFuture) future;
if (f.getRequestHeader("Sec-WebSocket-Accept") != null) {
f.updateWebSocketProtocol();
WebSocketFuture f2 = new WebSocketFutureImpl(session.getContext());
f2.write("{action: \"add-user\", username: \"火星人\"}");
// f2.write("{\"action\":999}");
session.flush(f2);
}
System.out.println(f.getRequestHeaders());
} else {
WebSocketFuture f = (WebSocketFuture) future;
System.out.println(f.getReadText());
}
}
};
ServerConfiguration configuration = new ServerConfiguration();
configuration.setSERVER_HOST("47.89.30.77");
// configuration.setSERVER_HOST("120.76.222.210");
// configuration.setSERVER_HOST("115.29.193.48");
// configuration.setSERVER_HOST("workerman.net");
configuration.setSERVER_PORT(7680);
// configuration.setSERVER_PORT(30005);
// configuration.setSERVER_PORT(29000);
// configuration.setSERVER_PORT(8280);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
connector.getContext().setBeatFutureFactory(new WebSocketBeatFutureFactory());
connector.getContext().setProtocolFactory(new ClientHTTPProtocolFactory());
connector.getContext().setSslContext(SSLUtil.initClient(true));
SocketSession session = connector.connect();
String url = "/web-socket-chat";
url = "/c1020";
HttpFuture future = new WebSocketUpgradeRequestFuture(session.getContext(), url);
// future.setRequestURL("ws://120.76.222.210:30005/");
// future.setResponseHeader("Host", "120.76.222.210:30005");
// future.setResponseHeader("Pragma", "no-cache");
// future.setResponseHeader("Cache-Control", "no-cache");
// future.setResponseHeader("User-Agent",
// "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36");
// future.setResponseHeader("Accept-Encoding", "gzip, deflate, sdch");
// future.setResponseHeader("Accept-Language", "zh-CN,zh;q=0.8");
// future.setRequestHeader("", "");
session.flush(future);
// ThreadUtil.sleep(1000);
// WebSocketReadFuture f2 = new WebSocketReadFutureImpl();
// f2.write("test");
// session.flush(f2);
ThreadUtil.sleep(999999999);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.http11.future.ClientHttpFuture in project baseio by generallycloud.
the class TestSimpleHttpClient method main.
public static void main(String[] args) throws Exception {
HttpIOEventHandle eventHandleAdaptor = new HttpIOEventHandle();
// ServerConfiguration c = new ServerConfiguration("localhost",80);
ServerConfiguration c = new ServerConfiguration("generallycloud.com", 443);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelConnector connector = new SocketChannelConnector(context);
SslContext sslContext = SSLUtil.initClient(true);
context.setProtocolFactory(new ClientHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setSslContext(sslContext);
SocketSession session = connector.connect();
HttpClient client = new HttpClient(session);
HttpFuture future = new ClientHttpFuture(context, "/test-show-memory");
HttpFuture res = client.request(future, 10000);
System.out.println();
System.out.println(new String(res.getBodyContent()));
System.out.println();
CloseUtil.close(connector);
}
Aggregations