• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java WebSocketImpl类的典型用法和代码示例

java 1次浏览

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

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

示例1: websocket

点赞 2

import com.koushikdutta.async.http.WebSocketImpl; //导入依赖的package包/类
public void websocket(String regex, final String protocol, final WebSocketRequestCallback callback) {
    get(regex, new HttpServerRequestCallback() {
        @Override
        public void onRequest(final AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
            boolean hasUpgrade = false;
            String connection = request.getHeaders().get("Connection");
            if (connection != null) {
                String[] connections = connection.split(",");
                for (String c: connections) {
                    if ("Upgrade".equalsIgnoreCase(c.trim())) {
                        hasUpgrade = true;
                        break;
                    }
                }
            }
            if (!"websocket".equalsIgnoreCase(request.getHeaders().get("Upgrade")) || !hasUpgrade) {
                response.code(404);
                response.end();
                return;
            }
            String peerProtocol = request.getHeaders().get("Sec-WebSocket-Protocol");
            if (!TextUtils.equals(protocol, peerProtocol)) {
                response.code(404);
                response.end();
                return;
            }
            callback.onConnected(new WebSocketImpl(request, response), request);
        }
    });
}
 

开发者ID:jacklongway,
项目名称:LiteSDK,
代码行数:31,
代码来源:AsyncHttpServer.java

示例2: websocket

点赞 2

import com.koushikdutta.async.http.WebSocketImpl; //导入依赖的package包/类
public void websocket(String regex, final String protocol, final WebSocketRequestCallback callback) {
    get(regex, new HttpServerRequestCallback() {
        @Override
        public void onRequest(final AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
            boolean hasUpgrade = false;
            String connection = request.getHeaders().getHeaders().get("Connection");
            if (connection != null) {
                String[] connections = connection.split(",");
                for (String c: connections) {
                    if ("Upgrade".equalsIgnoreCase(c.trim())) {
                        hasUpgrade = true;
                        break;
                    }
                }
            }
            if (!"websocket".equalsIgnoreCase(request.getHeaders().getHeaders().get("Upgrade")) || !hasUpgrade) {
                response.responseCode(404);
                response.end();
                return;
            }
            String peerProtocol = request.getHeaders().getHeaders().get("Sec-WebSocket-Protocol");
            if (!TextUtils.equals(protocol, peerProtocol)) {
                response.responseCode(404);
                response.end();
                return;
            }
            callback.onConnected(new WebSocketImpl(request, response), request.getHeaders());
        }
    });
}
 

开发者ID:xiaoshutong,
项目名称:AndroidNio,
代码行数:31,
代码来源:AsyncHttpServer.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)