本文整理了Java中com.neovisionaries.ws.client.WebSocket.sendText()
方法的一些代码示例,展示了WebSocket.sendText()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocket.sendText()
方法的具体详情如下:
包路径:com.neovisionaries.ws.client.WebSocket
类名称:WebSocket
方法名:sendText
[英]Send a text message to the server.
This method is an alias of #sendFrame(WebSocketFrame) (WebSocketFrame.WebSocketFrame#createTextFrame(String) (message)).
If you want to send a text frame that is to be followed by continuation frames, use #sendText(String,boolean) with fin=false.
[中]向服务器发送文本消息。
此方法是#sendFrame(WebSocketFrame)(WebSocketFrame.WebSocketFrame#createTextFrame(String)(message))的别名。
如果要发送后跟连续帧的文本帧,请使用#sendText(String,boolean)和fin=false。
代码示例来源:origin: DV8FromTheWorld/JDA
protected void send(String message)
{
LOG.trace("<- {}", message);
socket.sendText(message);
}
代码示例来源:origin: DV8FromTheWorld/JDA
protected boolean send(String message, boolean skipQueue)
{
if (!connected)
return false;
long now = System.currentTimeMillis();
if (this.ratelimitResetTime <= now)
{
this.messagesSent.set(0);
this.ratelimitResetTime = now + 60000;//60 seconds
this.printedRateLimitMessage = false;
}
//Allows 115 messages to be sent before limiting.
if (this.messagesSent.get() <= 115 || (skipQueue && this.messagesSent.get() <= 119)) //technically we could go to 120, but we aren't going to chance it
{
LOG.trace("<- {}", message);
socket.sendText(message);
this.messagesSent.getAndIncrement();
return true;
}
else
{
if (!printedRateLimitMessage)
{
LOG.warn("Hit the WebSocket RateLimit! This can be caused by too many presence or voice status updates (connect/disconnect/mute/deaf). " +
"Regular: {} Voice: {} Chunking: {}", ratelimitQueue.size(), queuedAudioConnections.size(), chunkSyncQueue.size());
printedRateLimitMessage = true;
}
return false;
}
}
代码示例来源:origin: net.dv8tion/JDA
public void send(String message)
{
socket.sendText(message);
}
代码示例来源:origin: net.dv8tion/JDA
public void send(String message)
{
socket.sendText(message);
}
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject eventObject = new JSONObject();
try {
eventObject.put("event", event);
eventObject.put("data", object);
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(eventObject.toString());
}
});
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject subscribeObject = new JSONObject();
try {
subscribeObject.put("event", "#unsubscribe");
subscribeObject.put("data", channel);
subscribeObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(subscribeObject.toString());
}
});
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject subscribeObject = new JSONObject();
try {
subscribeObject.put("event", "#subscribe");
JSONObject object = new JSONObject();
object.put("channel", channel);
subscribeObject.put("data", object);
subscribeObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(subscribeObject.toString());
}
});
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject publishObject = new JSONObject();
try {
publishObject.put("event", "#publish");
JSONObject object = new JSONObject();
object.put("channel", channel);
object.put("data", data);
publishObject.put("data", object);
publishObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(publishObject.toString());
}
});
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject eventObject = new JSONObject();
acks.put(counter.longValue(), getAckObject(event, ack));
try {
eventObject.put("event", event);
eventObject.put("data", object);
eventObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(eventObject.toString());
}
});
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject subscribeObject = new JSONObject();
try {
subscribeObject.put("event", "#unsubscribe");
subscribeObject.put("data", channel);
acks.put(counter.longValue(), getAckObject(channel, ack));
subscribeObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(subscribeObject.toString());
}
});
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject subscribeObject = new JSONObject();
try {
subscribeObject.put("event", "#subscribe");
JSONObject object = new JSONObject();
acks.put(counter.longValue(), getAckObject(channel, ack));
object.put("channel", channel);
subscribeObject.put("data", object);
subscribeObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(subscribeObject.toString());
}
});
代码示例来源:origin: blockchain/Android-Merchant-App
private void send(String message) {
//Make sure each message is only sent once per socket lifetime
if(!sentMessageSet.contains(message)) {
try {
if (mConnection != null && mConnection.isOpen()) {
mConnection.sendText(message);
sentMessageSet.add(message);
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
// Log.d("WebSocketHandler", "Message sent already: "+message);
}
}
代码示例来源:origin: io.github.sac/SocketclusterClientJava
public void run() {
JSONObject publishObject = new JSONObject();
try {
publishObject.put("event", "#publish");
JSONObject object = new JSONObject();
acks.put(counter.longValue(), getAckObject(channel, ack));
object.put("channel", channel);
object.put("data", data);
publishObject.put("data", object);
publishObject.put("cid", counter.getAndIncrement());
} catch (JSONException e) {
e.printStackTrace();
}
ws.sendText(publishObject.toString());
}
});
代码示例来源:origin: Javacord/Javacord
/**
* Sends the resume packet.
*
* @param websocket The websocket the resume packet should be sent to.
*/
private void sendResume(WebSocket websocket) {
ObjectNode resumePacket = JsonNodeFactory.instance.objectNode()
.put("op", GatewayOpcode.RESUME.getCode());
resumePacket.putObject("d")
.put("token", api.getPrefixedToken())
.put("session_id", sessionId)
.put("seq", lastSeq);
logger.debug("Sending resume packet");
websocket.sendText(resumePacket.toString());
}
代码示例来源:origin: io.github.sac/SocketclusterClientJava
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
/**
* Code for sending handshake
*/
counter.set(1);
if (strategy != null)
strategy.setAttmptsMade(0);
JSONObject handshakeObject = new JSONObject();
handshakeObject.put("event", "#handshake");
JSONObject object = new JSONObject();
object.put("authToken", AuthToken);
handshakeObject.put("data", object);
handshakeObject.put("cid", counter.getAndIncrement());
websocket.sendText(handshakeObject.toString());
listener.onConnected(Socket.this, headers);
super.onConnected(websocket, headers);
}
代码示例来源:origin: twitch4j/twitch4j
/**
* Send IRC Command
*
* @param command IRC Command
*/
private void sendCommand(String command) {
// will send command if connection has been established
if (connectionState.equals(TMIConnectionState.CONNECTED) || connectionState.equals(TMIConnectionState.CONNECTING)) {
// command will be uppercase.
this.webSocket.sendText(command);
} else {
log.warn("Can't send IRC-WS Command [{}]", command);
}
}
代码示例来源:origin: twitch4j/twitch4j
/**
* Send WS Message
*
* @param command IRC Command
*/
private void sendCommand(String command) {
// will send command if connection has been established
if (connectionState.equals(TMIConnectionState.CONNECTED) || connectionState.equals(TMIConnectionState.CONNECTING)) {
// command will be uppercase.
this.webSocket.sendText(command);
} else {
log.warn("Can't send IRC-WS Command [{}]", command);
}
}
代码示例来源:origin: Javacord/Javacord
/**
* Sends the update status packet.
*/
public void updateStatus() {
Optional<Activity> activity = api.getActivity();
ObjectNode updateStatus = JsonNodeFactory.instance.objectNode()
.put("op", GatewayOpcode.STATUS_UPDATE.getCode());
ObjectNode data = updateStatus.putObject("d")
.put("status", api.getStatus().getStatusString())
.put("afk", false)
.putNull("since");
ObjectNode activityJson = data.putObject("game");
activityJson.put("name", activity.isPresent() ? activity.get().getName() : null);
activityJson.put("type", activity.map(g -> g.getType().getId()).orElse(0));
activity.ifPresent(g -> g.getStreamingUrl().ifPresent(url -> activityJson.put("url", url)));
logger.debug("Updating status (content: {})", updateStatus);
websocket.get().sendText(updateStatus.toString());
}
代码示例来源:origin: Javacord/Javacord
/**
* Sends the voice state update packet.
*
* @param server The server to send the voice state update for. Can be {@code null} if {@code channel} is given.
* @param channel The channel to connect to or {@code null} to disconnect from voice.
* @param selfMuted Whether to self-mute on the given server. If {@code null}, current state remains unchanged.
* @param selfDeafened Whether to self-deafen on the given server. If {@code null}, current state remains unchanged.
*/
public void sendVoiceStateUpdate(
Server server, ServerVoiceChannel channel, Boolean selfMuted, Boolean selfDeafened) {
ObjectNode updateVoiceStatePacket = JsonNodeFactory.instance.objectNode()
.put("op", GatewayOpcode.VOICE_STATE_UPDATE.getCode());
if (server == null) {
if (channel == null) {
throw new IllegalArgumentException("Either server or channel must be given");
}
server = channel.getServer();
}
User yourself = api.getYourself();
updateVoiceStatePacket.putObject("d")
.put("guild_id", server.getIdAsString())
.put("channel_id", (channel == null) ? null : channel.getIdAsString())
.put("self_mute", (selfMuted == null) ? server.isSelfMuted(yourself) : selfMuted)
.put("self_deaf", (selfDeafened == null) ? server.isSelfDeafened(yourself) : selfDeafened);
logger.debug("Sending VOICE_STATE_UPDATE packet for channel {} on server {}", channel, server);
websocket.get().sendText(updateVoiceStatePacket.toString());
}
代码示例来源:origin: delight-im/Android-DDP
/**
* Sends a string over the websocket
*
* @param message the string to send
*/
private void send(final String message) {
log(TAG);
log(" send");
log(" message == "+message);
if (message == null) {
throw new IllegalArgumentException("You cannot send `null` messages");
}
if (mConnected) {
log(" dispatching");
if (mWebSocket != null) {
mWebSocket.sendText(message);
}
else {
throw new IllegalStateException("You must have called the 'connect' method before you can send data");
}
}
else {
log(" queueing");
mQueuedMessages.add(message);
}
}
内容来源于网络,如有侵权,请联系作者删除!