当前位置: 首页>>代码示例>>Java>>正文


Java TextMessage类代码示例

本文整理汇总了Java中org.springframework.web.socket.TextMessage的典型用法代码示例。如果您正苦于以下问题:Java TextMessage类的具体用法?Java TextMessage怎么用?Java TextMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextMessage类属于org.springframework.web.socket包,在下文中一共展示了TextMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendPlayEnd

import org.springframework.web.socket.TextMessage; //导入依赖的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: handleTextMessage

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) throws Exception
{
	WebSocketMessage message = objectMapper.readerFor(WebSocketMessage.class).readValue(textMessage.getPayload());
	log.info("Got message {} from session {}.", message, session.getId());
	if (message instanceof SubscribeRequest)
	{
		SubscribeRequest subscribeRequest = (SubscribeRequest) message;
		this.subscribeBusinessService.addSubscription(session, subscribeRequest.getBucketName());
	}
	else if (message instanceof PublishRequest)
	{
		PublishRequest publishRequest = (PublishRequest) message;
		this.publishBucketBusinessService.publish(new BucketDto(publishRequest.getBucketName(), publishRequest.getData()));
	}
	else
	{
		log.debug("Unhandled message {} ignored.", message);
	}
}
 
开发者ID:tmply,项目名称:tmply,代码行数:20,代码来源:WebSocketController.java

示例3: sendWebSocketMessage

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
public void sendWebSocketMessage(ProgressVo msg) {
	if (webSocketSession == null || !webSocketSession.isOpen()) {
		return;
	}
	int curPercent = 0;
	if (msg.getMax() != 0) {
		curPercent = (int) Math.floor(Double.valueOf(msg.getProgress()) / msg.getMax() * 100);
	}
	if (lastPercentProcess != curPercent) {
		lastPercentProcess = curPercent;
		Gson gson = new Gson();
		String jsonStr = gson.toJson(msg);
		TextMessage message = new TextMessage(jsonStr);
		try {
			webSocketSession.sendMessage(message);
		} catch (Exception e) {
			try {
				webSocketSession.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:26,代码来源:JsonGeometryQueryAction.java

示例4: handleTextMessage

import org.springframework.web.socket.TextMessage; //导入依赖的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: afterConnectionEstablished

import org.springframework.web.socket.TextMessage; //导入依赖的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

示例6: sendMessage

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
public void sendMessage(WampMessage msg) throws IOException {
	try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
			JsonGenerator generator = this.jsonFactory.createGenerator(bos)) {
		generator.writeStartArray();

		msg.serialize(generator);
		generator.writeEndArray();
		generator.close();

		if (this.isBinary) {
			this.webSocketSession.sendMessage(new BinaryMessage(bos.toByteArray()));
		}
		else {
			this.webSocketSession.sendMessage(new TextMessage(bos.toByteArray()));
		}
	}
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:18,代码来源:WampClient.java

示例7: handleTextMessage

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message)
		throws Exception {

	try {
		WampMessage wampMessage = WampMessage.deserialize(this.jsonFactory,
				message.asBytes());

		if (wampMessage instanceof WelcomeMessage) {
			this.welcomeMessageFuture.complete((WelcomeMessage) wampMessage);
		}
		else {
			this.receivedMessages.add(wampMessage);
			if (this.receivedMessages.size() == this.noOfResults) {
				this.messageFuture.complete(this.receivedMessages);
			}

		}

	}
	catch (IOException e) {
		this.welcomeMessageFuture.completeExceptionally(e);
		this.messageFuture.completeExceptionally(e);
	}
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:26,代码来源:CompletableFutureWebSocketHandler.java

示例8: broadcast

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
/**
 * 广播给用户信息 可以除开某个id
 *
 * @param msg    信息
 * @param except 除开的id
 */
public void broadcast(TextMessage msg, String except) {
    threadPool.execute(() -> {
        for (Map.Entry<String, WebSocketSession> entry : clients.entrySet()) {
            WebSocketSession se = entry.getValue();
            if (StringUtils.equals(except, entry.getKey()) || !se.isOpen()) {
                continue;
            }
            //noinspection SynchronizationOnLocalVariableOrMethodParameter
            synchronized (se) {
                try {
                    se.sendMessage(msg);
                } catch (IOException e) {
                    LOGGER.error("[DrawGuess]发送消息\"{}\"出错", msg.getPayload(), e);
                }
            }
        }
    });

}
 
开发者ID:csdbianhua,项目名称:telemarket-skittle-alley,代码行数:26,代码来源:DrawGuessWebSocket.java

示例9: handleTextMessage

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    Map<String, String> messageMap = getMessageMap(message);

    if (messageMap.containsKey("type")) {
        String type = messageMap.get("type");

        switch (type) {
            case "TERMINAL_INIT":
                terminalService.onTerminalInit();
                break;
            case "TERMINAL_READY":
                terminalService.onTerminalReady();
                break;
            case "TERMINAL_COMMAND":
                terminalService.onCommand(messageMap.get("command"));
                break;
            case "TERMINAL_RESIZE":
                terminalService.onTerminalResize(messageMap.get("columns"), messageMap.get("rows"));
                break;
            default:
                throw new RuntimeException("Unrecodnized action");
        }
    }
}
 
开发者ID:javaterminal,项目名称:cloudterm,代码行数:26,代码来源:TerminalSocket.java

示例10: sendMsg

import org.springframework.web.socket.TextMessage; //导入依赖的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

示例11: sendGroupChat

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
public int sendGroupChat(int userId, int notebookId, Date datetime, String content) {

        //receive
        String username = userInfoDao.getUserInfoById(userId).getUsername();
        String avatar = userDao.getUserById(userId).getAvatar();
        GroupChat groupChat = groupChatDao.getGroupChatById(notebookId);
        Message msg = new Message(userId, username, avatar, notebookId, content, new Date());
        //store
        if(groupChat == null){
            groupChatDao.addGroupChat(new GroupChat(notebookId, new ArrayList<String>()));
            groupChat = groupChatDao.getGroupChatById(notebookId);
        }
        ArrayList<String> contents = groupChat.getContents();
        JsonObject json = new JsonObject();
        json.addProperty("uid", userId);
        json.addProperty("datetime", datetime.toString());
        json.addProperty("content", content);
        contents.add(json.toString());
        groupChat.setContents(contents);
        groupChatDao.updateGroupChat(groupChat);
        //broadcast
        websocketHandler.sendMessageToGroup(userId, notebookId, new TextMessage(new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(msg)));
        return 0;
    }
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:25,代码来源:CooperateServiceImpl.java

示例12: handleTextMessage

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws IOException {
	String country = message.getPayload();
	String reply="No data available";
	if(country.equals("India"))
	{
		reply="DELHI";
	}
	else if(country.equals("USA"))
	{
		reply="Washington,D.C";
	}
	System.out.println("handling message");
	
	for(WebSocketSession webSsession:sessions)
	{
		session.sendMessage(new TextMessage(reply));	
	}
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:20,代码来源:MyMessageHandler.java

示例13: handleTextMessage

import org.springframework.web.socket.TextMessage; //导入依赖的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

示例14: send

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
@Override
public void send(PluginWebsocketMsg<?> wsMsg) throws IOException {
    PluginWebsocketSessionRef sessionRef = wsMsg.getSessionRef();
    String externalId = sessionRef.getSessionId();
    log.debug("[{}] Processing {}", externalId, wsMsg);
    String internalId = externalSessionMap.get(externalId);
    if (internalId != null) {
        SessionMetaData sessionMd = internalSessionMap.get(internalId);
        if (sessionMd != null) {
            if (wsMsg instanceof TextPluginWebSocketMsg) {
                String payload = ((TextPluginWebSocketMsg) wsMsg).getPayload();
                sessionMd.session.sendMessage(new TextMessage(payload));
            }
        } else {
            log.warn("[{}][{}] Failed to find session by internal id", externalId, internalId);
        }
    } else {
        log.warn("[{}] Failed to find session by external id", externalId);
    }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:21,代码来源:PluginWebSocketHandler.java

示例15: handleTextMessage

import org.springframework.web.socket.TextMessage; //导入依赖的package包/类
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    FrameMessage frameMessage = objectMapper.readValue(message.getPayload(), FrameMessage.class);
    List<BindedMethod> callbackList = messageCallbacks.get(frameMessage.getType());
    Object messageData;
    Class<?> messageType;
    boolean isUnhandledMessage = true;
    if (callbackList != null && 0 < callbackList.size())
        for (BindedMethod method : callbackList) {
            isUnhandledMessage = false;
            messageType = method.getParameterTypes()[1];
            messageData = objectMapper.treeToValue(frameMessage.getData(), messageType);
            method.invoke(session, messageData);
        }

    if (isUnhandledMessage) {
        String errorMessage = "Received message type is unhandled: " + frameMessage.getType();
        throw new Exception(errorMessage);
    }
}
 
开发者ID:apostx,项目名称:broadcast_server,代码行数:21,代码来源:MessageRouter.java


注:本文中的org.springframework.web.socket.TextMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。