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


Java WebSocketFrame类代码示例

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


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

示例1: onDisconnected

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
    identity.CONNECTION = Identity.Connection.OFFLINE;

    final int closeCode;
    final String closeReason;
    if (closedByServer) {
        closeCode = serverCloseFrame.getCloseCode();
        closeReason = serverCloseFrame.getCloseReason();
    } else {
        closeCode = clientCloseFrame.getCloseCode();
        closeReason = clientCloseFrame.getCloseReason();
    }

    identity.getEventManager().dispatchEvent(new DisconnectEvent(identity, this, 0, closedByServer, closeCode, closeReason));
    LOG.log(LogLevel.INFO, "[CONNECTION] Disconnected [Code: " + closeCode + "][Reason: " + closeReason + "]");
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:18,代码来源:GatewayAdaptor.java

示例2: onDisconnected

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
/**
 * 连接断开  主动关闭webSocket时回调
 *
 * @param websocket
 * @param serverCloseFrame
 * @param clientCloseFrame
 * @param closedByServer
 * @throws Exception
 */
@Override
public void onDisconnected(WebSocket websocket, final WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
    super.onDisconnected(websocket, serverCloseFrame, clientCloseFrame, closedByServer);
    e("webSocket断开" + mWebSocket);
    webSocketState = WEB_SOCKET_CLOSE;
    //final int closeCode = serverCloseFrame.getCloseCode();
    //final String closeReason = serverCloseFrame.getCloseReason();

    onMain(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < mListeners.size(); i++) {
                RWebSocketListener listener = mListeners.get(i);
                listener.disConnectWebsocket();
            }
        }
    });
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:28,代码来源:RWebSocket.java

示例3: onTextFrame

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
    try {
        String response = frame.getPayloadText();
        Gson gson = new Gson();

        Type GetLimitiOrdersResponse = new TypeToken<WitnessResponse<ArrayList<Market>>>() {
        }.getType();
        WitnessResponse<ArrayList<Market>> witnessResponse = gson.fromJson(response, GetLimitiOrdersResponse);
        if (witnessResponse.error != null) {
            this.mListener.onError(witnessResponse.error);
        } else {
            this.mListener.onSuccess(witnessResponse);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    websocket.disconnect();
}
 
开发者ID:kenCode-de,项目名称:smartcoins-wallet,代码行数:20,代码来源:GetLimitOrders.java

示例4: onCloseFrame

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onCloseFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
    int closeCode = frame.getCloseCode();
    String closeReason = frame.getCloseReason();

    log.info("Websocket closed with status '" + closeCode + "' and reason '" + closeReason + "'");
    socketCloseLatch.countDown();
}
 
开发者ID:CatalystCode,项目名称:SpeechToText-WebSockets-Java,代码行数:9,代码来源:NvMessageReceiver.java

示例5: onDisconnected

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onDisconnected(WebSocket websocket,
                           WebSocketFrame serverCloseFrame,
                           WebSocketFrame clientCloseFrame,
                           boolean closedByServer) throws Exception {
    callOnDisconnected();
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:8,代码来源:ConnectionReceiver.java

示例6: onDisconnected

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onDisconnected(WebSocket websocket,
                           WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame,
                           boolean closedByServer) throws Exception {
    if (websocket == mWS) {
        mConnectionStatusFuture.setDone(false);
        mLatch.countDown();
    }
}
 
开发者ID:gbizzotto,项目名称:dapay,代码行数:10,代码来源:BlinktradeAPI.java

示例7: onDisconnected

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer)
{
    LOG.debug("The Audio connection was closed!");
    LOG.debug("By remote? " + closedByServer);
    if (serverCloseFrame != null)
    {
        LOG.debug("Reason: " + serverCloseFrame.getCloseReason());
        LOG.debug("Close code: " + serverCloseFrame.getCloseCode());
        final int code = serverCloseFrame.getCloseCode();
        final VoiceCode.Close closeCode = VoiceCode.Close.from(code);
        switch (closeCode)
        {
            case SERVER_NOT_FOUND:
            case SERVER_CRASH:
            case INVALID_SESSION:
                this.close(ConnectionStatus.ERROR_CANNOT_RESUME);
                break;
            case AUTHENTICATION_FAILED:
                this.close(ConnectionStatus.DISCONNECTED_AUTHENTICATION_FAILURE);
                break;
            default:
                this.reconnect(ConnectionStatus.ERROR_LOST_CONNECTION);
        }
        return;
    }
    if (clientCloseFrame != null)
    {
        LOG.debug("ClientReason: " + clientCloseFrame.getCloseReason());
        LOG.debug("ClientCode: " + clientCloseFrame.getCloseCode());
        if (clientCloseFrame.getCloseCode() != 1000)
        {
            // unexpected close -> error -> attempt resume
            this.reconnect(ConnectionStatus.ERROR_LOST_CONNECTION);
            return;
        }
    }
    this.close(ConnectionStatus.NOT_CONNECTED);
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA-Audio,代码行数:40,代码来源:AudioWebSocket.java

示例8: onDisconnected

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
    mainHandler.post(new Runnable() {
        @Override
        public void run() {
            onWebSocketDisconnected();
        }
    });
}
 
开发者ID:asadmshah,项目名称:drawnearby,代码行数:10,代码来源:BaseConnection.java

示例9: onTextFrame

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
    String response = frame.getPayloadText();
    System.out.println("<<< "+response);
    Gson gson = new Gson();
    BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
    if(baseResponse.error != null){
        mListener.onError(baseResponse.error);
        if(mOneTime){
            websocket.disconnect();
        }
    }else{
        currentId++;
        ArrayList<Serializable> emptyParams = new ArrayList<>();
        if(baseResponse.id == LOGIN_ID){
            ApiCall getRelativeAccountHistoryId = new ApiCall(1, RPC.CALL_HISTORY, emptyParams, RPC.VERSION, currentId);
            websocket.sendText(getRelativeAccountHistoryId.toJsonString());
        }else if(baseResponse.id == GET_HISTORY_ID){
            Type ApiIdResponse = new TypeToken<WitnessResponse<Integer>>() {}.getType();
            WitnessResponse<Integer> witnessResponse = gson.fromJson(response, ApiIdResponse);
            apiId = witnessResponse.result.intValue();

            sendRelativeAccountHistoryRequest();
        }else if(baseResponse.id >= GET_HISTORY_DATA){
            Type RelativeAccountHistoryResponse = new TypeToken<WitnessResponse<List<HistoricalTransfer>>>(){}.getType();
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.registerTypeAdapter(TransferOperation.class, new TransferOperation.TransferDeserializer());
            gsonBuilder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer());
            WitnessResponse<List<HistoricalTransfer>> transfersResponse = gsonBuilder.create().fromJson(response, RelativeAccountHistoryResponse);
            mListener.onSuccess(transfersResponse);
        }
    }
}
 
开发者ID:kenCode-de,项目名称:smartcoins-wallet,代码行数:34,代码来源:GetRelativeAccountHistory.java

示例10: DisconnectEvent

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
public DisconnectEvent(JDA api, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer,
                       OffsetDateTime disconnectTime)
{
    super(api, -1);
    this.serverCloseFrame = serverCloseFrame;
    this.clientCloseFrame = clientCloseFrame;
    this.closedByServer = closedByServer;
    this.disconnectTime = disconnectTime;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:10,代码来源:DisconnectEvent.java

示例11: onDisconnected

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onDisconnected(final WebSocket websocket, final WebSocketFrame serverCloseFrame,
        final WebSocketFrame clientCloseFrame, final boolean closedByServer) throws Exception {
    if (closedByServer) {
        triggerOnDisconnectEvent(serverCloseFrame.getCloseCode(), serverCloseFrame.getCloseReason());
    } else {
        triggerOnDisconnectEvent(clientCloseFrame.getCloseCode(), clientCloseFrame.getCloseReason());
    }
}
 
开发者ID:czyzby,项目名称:gdx-lml,代码行数:10,代码来源:NvWebSocketListener.java

示例12: onFrame

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
    OPCode code = OPCode.getByKey(frame.getOpcode());
    handleOPCode(code, frame.getPayloadText());
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:6,代码来源:GatewayAdaptor.java

示例13: start

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
public void start() {
    if (socketThread == null) {
        socketThread = new Thread(new Runnable() {
            @Override
            public void run() {
                Socket socket = new Socket("ws://" + config.host + ":" + config.port + "/socketcluster/");
                socket.setListener(new BasicListener() {
                    @Override
                    public void onConnected(Socket socket, Map<String, List<String>> headers) {
                        System.out.println("Connected");
                    }

                    @Override
                    public void onDisconnected(Socket socket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
                        System.out.println("Disconnected: " + closedByServer);
                    }

                    @Override
                    public void onConnectError(Socket socket, WebSocketException exception) {
                        exception.printStackTrace();
                    }

                    @Override
                    public void onAuthentication(Socket socket, Boolean status) {

                    }

                    @Override
                    public void onSetAuthToken(String token, Socket socket) {

                    }
                });
                socket.connect();

                while (true) {
                    try {
                        Message<S, A> message = queue.take();
                        if (message == Message.END) {
                            socket.disconnect();
                            break;
                        }
                        JSONObject json = new JSONObject();
                        json.put("type", "ACTION");
                        JSONObject action = new JSONObject();
                        action.put("action", jsonify(message.action, true));
                        action.put("timestamp", new Date().getTime());
                        json.put("action", action);
                        json.put("payload", jsonify(message.state, false));
                        json.put("instanceId", store.getClass());

                        socket.emit("log-noid", json);
                    } catch (InterruptedException e) {
                        break;
                    } catch (JSONException e) {
                        break;
                    }
                }
            }
        });
        socketThread.start();
    }
}
 
开发者ID:evant,项目名称:redux,代码行数:63,代码来源:MonitorMiddleware.java

示例14: onTextFrame

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
    String response = frame.getPayloadText();
    System.out.println("<<< "+response);
    Gson gson = new Gson();
    BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
    if(baseResponse.error != null){
        mListener.onError(baseResponse.error);
        if(mOneTime){
            websocket.disconnect();
        }
    }else{
        currentId++;
        ArrayList<Serializable> emptyParams = new ArrayList<>();
        if(baseResponse.id == LOGIN_ID){
            ApiCall getRelativeAccountHistoryId = new ApiCall(1, RPC.CALL_HISTORY, emptyParams, RPC.VERSION, currentId);
            websocket.sendText(getRelativeAccountHistoryId.toJsonString());
        } else if(baseResponse.id == GET_HISTORY_ID){
            Type ApiIdResponse = new TypeToken<WitnessResponse<Integer>>() {}.getType();
            WitnessResponse<Integer> witnessResponse = gson.fromJson(response, ApiIdResponse);
            apiId = witnessResponse.result.intValue();

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss");

            ArrayList<Serializable> params = new ArrayList<>();
            params.add(this.base.getObjectId());
            params.add(this.quote.getObjectId());
            params.add(this.bucket);
            params.add(dateFormat.format(this.start));
            params.add(dateFormat.format(this.end));

            ApiCall getRelativeAccountHistoryCall = new ApiCall(apiId, RPC.CALL_GET_MARKET_HISTORY, params, RPC.VERSION, currentId);
            websocket.sendText(getRelativeAccountHistoryCall.toJsonString());
        }else if(baseResponse.id >= GET_HISTORY_DATA){
            GsonBuilder builder = new GsonBuilder();
            Type MarketHistoryResponse = new TypeToken<WitnessResponse<List<BucketObject>>>(){}.getType();
            builder.registerTypeAdapter(BucketObject.class, new BucketObject.BucketDeserializer());
            WitnessResponse<List<BucketObject>> marketHistoryResponse = builder.create().fromJson(response, MarketHistoryResponse);
            mListener.onSuccess(marketHistoryResponse);
        }
    }
}
 
开发者ID:kenCode-de,项目名称:smartcoins-wallet,代码行数:43,代码来源:GetMarketHistory.java

示例15: onFrameSent

import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
    if(frame.isTextFrame())
        System.out.println(">>> "+frame.getPayloadText());
}
 
开发者ID:kenCode-de,项目名称:smartcoins-wallet,代码行数:6,代码来源:GetMarketHistory.java


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