本文整理汇总了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 + "]");
}
示例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();
}
}
});
}
示例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();
}
示例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();
}
示例5: onDisconnected
import com.neovisionaries.ws.client.WebSocketFrame; //导入依赖的package包/类
@Override
public void onDisconnected(WebSocket websocket,
WebSocketFrame serverCloseFrame,
WebSocketFrame clientCloseFrame,
boolean closedByServer) throws Exception {
callOnDisconnected();
}
示例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();
}
}
示例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);
}
示例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();
}
});
}
示例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);
}
}
}
示例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;
}
示例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());
}
}
示例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());
}
示例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();
}
}
示例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);
}
}
}
示例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());
}