本文整理汇总了Java中com.neovisionaries.ws.client.WebSocket.sendText方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocket.sendText方法的具体用法?Java WebSocket.sendText怎么用?Java WebSocket.sendText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.neovisionaries.ws.client.WebSocket
的用法示例。
在下文中一共展示了WebSocket.sendText方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConnected
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
// Request capabilities
websocket.sendText("CAP REQ :twitch.tv/membership");
websocket.sendText("CAP REQ :twitch.tv/commands");
websocket.sendText("CAP REQ :twitch.tv/tags");
// Log in
websocket.sendText("PASS oauth:" + oAuth);
websocket.sendText("NICK " + username);
messageQueue.setWebSocket(websocket);
}
示例2: onTextMessage
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
@Override
public void onTextMessage(WebSocket websocket, String text) throws Exception {
// Catch server emitting PING, respond and break
if (text.contains(IrcCommand.PING.toString())) {
websocket.sendText(IrcCommand.PONG.toString());
return;
}
// Split multiline mesages and handle each as seperate message
String[] msgs = text.trim().split("\r\n");
Arrays.stream(msgs)
.filter(msg -> msg.indexOf(':') == 0 || msg.indexOf('@') == 0)
.forEach(s -> this.parseMessage(websocket, s));
}
示例3: handShake
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
private void handShake(WebSocket ws)
{
HandshakeRequest request = new HandshakeRequest();
if (SocketService.hasToken())
{
request.data = new TokenRequest(SocketService.getToken());
}
ws.sendText((new Gson()).toJson(request));
}
示例4: onConnected
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
mWebsocket = websocket;
ArrayList<Serializable> loginParams = new ArrayList<>();
loginParams.add(null);
loginParams.add(null);
ApiCall loginCall = new ApiCall(1, RPC.CALL_LOGIN, loginParams, RPC.VERSION, currentId);
websocket.sendText(loginCall.toJsonString());
}
示例5: onTextFrame
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的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);
}
}
}
示例6: onConnected
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
ArrayList<Serializable> accountParams = new ArrayList<>();
accountParams.add(this.a);
accountParams.add(this.b);
accountParams.add(this.limit);
ApiCall getAccountByName = new ApiCall(0, RPC.CALL_GET_LIMIT_ORDERS, accountParams, "2.0", 1);
websocket.sendText(getAccountByName.toJsonString());
}
示例7: on001
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
protected void on001(WebSocket webSocket) {
webSocket.sendText("JOIN #" + channelName);
logger.info("Joined channel #{}", channelName);
messageQueue.start();
eventBus.post(new IrcChannelJoinedEvent(channelName, username));
}
示例8: handleRequest
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
private void handleRequest(WebSocket ws, JsonObject o)
{
String error = null;
boolean noResponse = false;
int cid = o.get("cid").getAsInt();
try
{
String event = o.get("event").getAsString();
switch (event)
{
case REMOVE_AUTH_TOKEN_REQUEST:
{
setAuthToken(null);
noResponse = responseCallback.onConnected();
break;
}
case SET_AUTH_TOKEN_REQUEST:
{
TokenRequest req = (new Gson()).fromJson(o.get("data"), TokenRequest.class);
setAuthToken(req);
noResponse = responseCallback.onAuthenticated();
break;
}
case EVENT_DISCONNECTED:
{
noResponse = responseCallback.onDisconnected((new Gson()).fromJson(o, DisconectedResponse.class));
break;
}
case PUBLISH_RESPONSE:
{
noResponse = responseCallback.onReceived(cid, o);
break;
}
default:
noResponse = responseCallback.onUnknown(ws, o.toString());
error = "No handler";
break;
}
} catch (Exception e)
{
error = e.getMessage();
noResponse = false;
}
if (!noResponse)
{
Response r = new Response(cid, error);
String text = (new Gson()).toJson(r);
ws.sendText(text);
}
}
示例9: pong
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的package包/类
private void pong(WebSocket ws)
{
ws.sendText(PONG_RESPONSE);
}
示例10: onTextFrame
import com.neovisionaries.ws.client.WebSocket; //导入方法依赖的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);
}
}
}