本文整理汇总了Java中org.springframework.web.socket.WebSocketSession.sendMessage方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocketSession.sendMessage方法的具体用法?Java WebSocketSession.sendMessage怎么用?Java WebSocketSession.sendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.socket.WebSocketSession
的用法示例。
在下文中一共展示了WebSocketSession.sendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendPlayEnd
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public void sendPlayEnd(WebSocketSession session) {
try {
JsonObject response = new JsonObject();
response.addProperty("id", "playEnd");
session.sendMessage(new TextMessage(response.toString()));
} catch (IOException e) {
log.error("Error sending playEndOfStream message", e);
}
// Release pipeline
pipeline.release();
this.webRtc = null;
}
示例2: afterConnectionEstablished
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public synchronized void afterConnectionEstablished(final WebSocketSession session) throws Exception {
super.afterConnectionEstablished(session);
session.sendMessage(new TextMessage("\nWeb-socket timer is on!\n"));
new Thread() {
@Override
public synchronized void run() {
try {
while (session.isOpen()) {
session.sendMessage(new TextMessage("" + new Date() + "\n"));
Thread.currentThread().wait(1000);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
.start();
}
示例3: sendMsg
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public static void sendMsg() {
try {
List<TaskInfo> taskInfos = new LinkedList<>();
for (Entry<String, HttpDownInfo> downInfoEntry : HttpDownServer.DOWN_CONTENT.entrySet()) {
HttpDownInfo httpDownInfo = downInfoEntry.getValue();
if (httpDownInfo.getTaskInfo().getStatus() != 0) {
taskInfos.add(httpDownInfo.getTaskInfo());
}
}
TextMessage message = new TextMessage(JSON.toJSONString(taskInfos));
for (Entry<String, WebSocketSession> entry : HttpDownServer.WS_CONTENT.entrySet()) {
WebSocketSession session = entry.getValue();
if (session.isOpen()) {
synchronized (session) {
session.sendMessage(message);
}
}
}
} catch (Exception e) {
HttpDownServer.LOGGER.warn("sendMsg",e);
}
}
示例4: handleTextMessage
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
super.handleTextMessage(session, message);
try {
getClient(session,null);
if (this.terminalClient != null ) {
if ( !terminalClient.isClosed()) {
terminalClient.write(message.getPayload());
}else {
session.close();
}
}
} catch (Exception e) {
session.sendMessage(new TextMessage("Sorry! opencron Terminal was closed, please try again. "));
terminalClient.disconnect();
session.close();
}
}
示例5: handleTextMessage
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
try {
log.info("[{}] Processing {}", session.getId(), message);
SessionMetaData sessionMd = internalSessionMap.get(session.getId());
if (sessionMd != null) {
actorService.process(new TextPluginWebSocketMsg(sessionMd.sessionRef, message.getPayload()));
} else {
log.warn("[{}] Failed to find session", session.getId());
session.close(CloseStatus.SERVER_ERROR.withReason("Session not found!"));
}
session.sendMessage(message);
} catch (IOException e) {
log.warn("IO error", e);
}
}
示例6: afterConnectionEstablished
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
ss = new SocketSession(session);
TextMessage message = new TextMessage("Socket session opened!");
session.sendMessage(message);
logger.info("Opened new session in instance " + this);
//boop();
}
示例7: handleTextMessage
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message)
throws Exception {
/*Thread thread = new Thread(new Runnable() {
public void run() {
boop();
}
});
thread.start();*/
this.logger.info("Received: " + message);
String msg = ss.getResponse(message.getPayload());
logger.info("Replying: " + msg);
session.sendMessage(new TextMessage(msg));
//session.close();
//this.messagePayload.set(message.getPayload());
//this.latch.countDown();
}
示例8: handleTextMessage
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message)
throws InterruptedException, IOException {
for(WebSocketSession webSocketSession : sessions) {
Map value = new Gson().fromJson(message.getPayload(), Map.class);
String[] data = value.get("data").toString().split(",");
// save data[2] as complaints inside the database
webSocketSession.sendMessage(new TextMessage("Dear " + data[0] + ", you complaint is now being processed..."));
}
}
示例9: handleErrorResponse
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
private void handleErrorResponse(Throwable throwable, WebSocketSession session, String responseId)
throws IOException {
stop(session);
log.error(throwable.getMessage(), throwable);
JsonObject response = new JsonObject();
response.addProperty("id", responseId);
response.addProperty("response", "rejected");
response.addProperty("message", throwable.getMessage());
session.sendMessage(new TextMessage(response.toString()));
}
示例10: sendTo
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public void sendTo(WebSocketMessage message, WebSocketSession receiverWebSocketSession)
{
try
{
String json = toJson(message);
receiverWebSocketSession.sendMessage(new TextMessage(json));
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
}
示例11: sendMessageToUsers
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
/**
* 给所有在线用户发送消息
*
* @param message
*/
public void sendMessageToUsers(TextMessage message) {
for (WebSocketSession user : users) {
try {
if (user.isOpen()) {
user.sendMessage(message);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例12: emit
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public void emit(String message) {
for (WebSocketSession webSocketSession : openSessions) {
try {
webSocketSession.sendMessage(new TextMessage(message));
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例13: sendMessage
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
protected void sendMessage(DataFormat dataFormat, WebSocketSession webSocketSession,
WampMessage msg) throws IOException {
JsonFactory useFactory = this.jsonFactory;
if (dataFormat == DataFormat.MSGPACK) {
useFactory = this.msgpackFactory;
}
else if (dataFormat == DataFormat.CBOR) {
useFactory = this.cborFactory;
}
else if (dataFormat == DataFormat.SMILE) {
useFactory = this.smileFactory;
}
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator generator = useFactory.createGenerator(bos)) {
generator.writeStartArray();
msg.serialize(generator);
generator.writeEndArray();
generator.close();
if (dataFormat == DataFormat.MSGPACK || dataFormat == DataFormat.CBOR
|| dataFormat == DataFormat.SMILE) {
webSocketSession.sendMessage(new BinaryMessage(bos.toByteArray()));
}
else {
webSocketSession.sendMessage(new TextMessage(bos.toByteArray()));
}
}
}
示例14: broadcastNewEmailMessage
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public void broadcastNewEmailMessage(EmailRecord email) throws IOException {
final String content = new ObjectMapper().writeValueAsString(email);
for (WebSocketSession webSocketSession : sessions) {
String inbox = emailWebSocketRoute.extractInboxName(webSocketSession.getUri());
if (email.getInbox().equals(inbox)) {
webSocketSession.sendMessage(new TextMessage(content));
}
}
}
示例15: sendErrorMessage
import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public void sendErrorMessage(WebSocketSession wsSession, String errorMessage, String incomingMessage) throws IOException {
JsonObject jsonMessage = new JsonObject();
jsonMessage.addProperty("type", "message.error");
String message = "Error: "+errorMessage+", your message: "+incomingMessage;
jsonMessage.addProperty("message", message);
synchronized (wsSession) {
TextMessage msg = new TextMessage(jsonMessage.toString().getBytes("UTF-8"));
wsSession.sendMessage(msg);
//wsSession.getBasicRemote().sendText(jsonMessage.toString());
}
}