当前位置: 首页>>代码示例>>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;未经允许,请勿转载。