当前位置: 首页>>代码示例>>Java>>正文


Java AsyncHttpServer.listen方法代码示例

本文整理汇总了Java中com.koushikdutta.async.http.server.AsyncHttpServer.listen方法的典型用法代码示例。如果您正苦于以下问题:Java AsyncHttpServer.listen方法的具体用法?Java AsyncHttpServer.listen怎么用?Java AsyncHttpServer.listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.koushikdutta.async.http.server.AsyncHttpServer的用法示例。


在下文中一共展示了AsyncHttpServer.listen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMaxAgePrivate

import com.koushikdutta.async.http.server.AsyncHttpServer; //导入方法依赖的package包/类
public void testMaxAgePrivate() throws Exception {
    AsyncHttpClient client = new AsyncHttpClient(AsyncServer.getDefault());
    ResponseCacheMiddleware cache = ResponseCacheMiddleware.addCache(client, new File(getContext().getFilesDir(), "AndroidAsyncTest"), 1024 * 1024 * 10);
    AsyncHttpServer httpServer = new AsyncHttpServer();
    try {
        httpServer.get("/uname/(.*)", new HttpServerRequestCallback() {
            @Override
            public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
                response.getHeaders().set("Date", HttpDate.format(new Date()));
                response.getHeaders().set("Cache-Control", "private, max-age=10000");
                response.send(request.getMatcher().group(1));
            }
        });

        AsyncServerSocket socket = httpServer.listen(AsyncServer.getDefault(), 0);
        int port = socket.getLocalPort();
        // clear the old cache
        cache.clear();

        client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();

        client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();


        assertEquals(cache.getCacheHitCount(), 1);
        assertEquals(cache.getNetworkCount(), 1);
    }
    finally {
        AsyncServer.getDefault().stop();
        client.getMiddleware().remove(cache);
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:33,代码来源:CacheTests.java

示例2: setUp

import com.koushikdutta.async.http.server.AsyncHttpServer; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    httpServer = new AsyncHttpServer();
    httpServer.setErrorCallback(new CompletedCallback() {
        @Override
        public void onCompleted(Exception ex) {
            fail();
        }
    });
    httpServer.listen(AsyncServer.getDefault(), 5000);
    

    httpServer.websocket("/ws", new WebSocketRequestCallback() {
        @Override
        public void onConnected(final WebSocket webSocket, AsyncHttpServerRequest request) {
            webSocket.setStringCallback(new StringCallback() {
                @Override
                public void onStringAvailable(String s) {
                    webSocket.send(s);
                }
            });
        }
    });
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:27,代码来源:WebSocketTests.java


注:本文中的com.koushikdutta.async.http.server.AsyncHttpServer.listen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。