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


Java AsyncServerSocket类代码示例

本文整理汇总了Java中com.koushikdutta.async.AsyncServerSocket的典型用法代码示例。如果您正苦于以下问题:Java AsyncServerSocket类的具体用法?Java AsyncServerSocket怎么用?Java AsyncServerSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testMaxAgePrivate

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的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: stop

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
public void stop() {
    if (mListeners != null) {
        for (AsyncServerSocket listener: mListeners) {
            listener.stop();
        }
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:8,代码来源:AsyncHttpServer.java

示例3: testProxy

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
public void testProxy() throws Exception {
        wasProxied = false;
        final AsyncServer proxyServer = new AsyncServer();
        try {
            AsyncProxyServer httpServer = new AsyncProxyServer(proxyServer) {
                @Override
                protected boolean onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
                    wasProxied = true;
                    return super.onRequest(request, response);
                }
            };

            AsyncServerSocket socket = httpServer.listen(proxyServer, 0);

//            client.getSocketMiddleware().enableProxy("localhost", 5555);

            AsyncHttpGet get = new AsyncHttpGet("http://www.clockworkmod.com");
            get.enableProxy("localhost", socket.getLocalPort());

            Future<String> ret = client.executeString(get, null);
            String data;
            assertNotNull(data = ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
            assertTrue(data.contains("ClockworkMod"));
            assertTrue(wasProxied);
        }
        finally {
            proxyServer.stop();
        }
    }
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:30,代码来源:HttpClientTests.java

示例4: getServerSocket

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
public AsyncServerSocket getServerSocket() {
    if (mServerWrapper != null) {
        return mServerWrapper.getServerSocket();
    } else {
        return null;
    }
}
 
开发者ID:amartinz,项目名称:DeviceControl,代码行数:8,代码来源:WebServerService.java

示例5: stop

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
public void stop() {
	if (mListeners != null) {
		for (AsyncServerSocket listener : mListeners) {
			listener.stop();
		}
	}
}
 
开发者ID:xiaoshutong,项目名称:AndroidNio,代码行数:8,代码来源:CShareServer.java

示例6: onListening

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
@Override
public void onListening(AsyncServerSocket socket) {
    Timber.i("Server listening on port %d", socket.getLocalPort());
}
 
开发者ID:maks,项目名称:UartBridge,代码行数:5,代码来源:SocketServer.java

示例7: onListening

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
@Override
public void onListening(AsyncServerSocket socket) {
    mListeners.add(socket);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:5,代码来源:AsyncHttpServer.java

示例8: listen

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
public AsyncServerSocket listen(AsyncServer server, int port) {
    return server.listen(null, port, mListenCallback);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:4,代码来源:AsyncHttpServer.java

示例9: onListening

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
@Override
public void onListening(AsyncServerSocket socket) {
	mListeners.add(socket);
}
 
开发者ID:xiaoshutong,项目名称:AndroidNio,代码行数:5,代码来源:CShareServer.java

示例10: onListening

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
public void onListening(AsyncServerSocket socket); 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:2,代码来源:ListenCallback.java

示例11: getServerSocket

import com.koushikdutta.async.AsyncServerSocket; //导入依赖的package包/类
public AsyncServerSocket getServerSocket() { return mServerSocket; } 
开发者ID:amartinz,项目名称:DeviceControl,代码行数:2,代码来源:ServerWrapper.java


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