當前位置: 首頁>>代碼示例>>Java>>正文


Java WebSocketSession.sendMessage方法代碼示例

本文整理匯總了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;
}
 
開發者ID:jake-kent,項目名稱:TLIVideoConferencingv2,代碼行數:14,代碼來源:PlayMediaPipeline.java

示例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();

}
 
開發者ID:herolynx,項目名稱:conf-modern-devops-k8s,代碼行數:21,代碼來源:WebSocketHandler.java

示例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);
  }
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:23,代碼來源:WsUtil.java

示例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();
	}
}
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:19,代碼來源:TerminalHandler.java

示例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);
    }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:17,代碼來源:PluginWebSocketHandler.java

示例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();
}
 
開發者ID:sinaa,項目名稱:train-simulator,代碼行數:10,代碼來源:WebSocketHandler.java

示例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();

}
 
開發者ID:sinaa,項目名稱:train-simulator,代碼行數:21,代碼來源:WebSocketHandler.java

示例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..."));
	}
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:12,代碼來源:HotlineSocketHandler.java

示例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()));
}
 
開發者ID:jake-kent,項目名稱:TLIVideoConferencingv2,代碼行數:11,代碼來源:CallHandler.java

示例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);
	}
}
 
開發者ID:tmply,項目名稱:tmply,代碼行數:13,代碼來源:DeliverBucketBusinessService.java

示例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();  
        }  
    }  
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:17,代碼來源:BinaryGeometryTemplateSocketHandler.java

示例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();
		}
	}
}
 
開發者ID:RuntimeTools,項目名稱:javametrics,代碼行數:10,代碼來源:JavametricsSpringSocketHandler.java

示例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()));
		}
	}
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:32,代碼來源:BaseWampTest.java

示例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));
        }
    }
}
 
開發者ID:Stubmarine,項目名稱:stubmarine,代碼行數:11,代碼來源:EmailWebSocketHandler.java

示例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());
	}
}
 
開發者ID:zralock,項目名稱:CTUConference,代碼行數:12,代碼來源:MessageSenderImpl.java


注:本文中的org.springframework.web.socket.WebSocketSession.sendMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。