小编mc *_*c j的帖子

WebSocket远程端点处于[TEXT_PARTIAL_WRITING]状态

我正在使用tomcat 8.0.15,spring 4.1.5.

我实现了3个强制函数来使用websocket,如下所示.这很简单.

private Map<String, WebSocketSession> map_users = new ConcurrentHashMap<>();
private Map<String, String> map_id = new ConcurrentHashMap<>();

public void afterConnectionEstablished(WebSocketSession wss) throws Exception {
    map_users.put(wss.getId(), wss);
}

public void afterConnectionClosed(WebSocketSession wss, CloseStatus cs) throws Exception {
    map_users.remove(wss.getId());

    // remove user
    String username = map_id.get(wss.getId());
    if (username != null) {
        map_id.remove(wss.getId());
        map_id.remove(username);
    }
}

public void handleTextMessage(WebSocketSession wss, TextMessage tm) throws Exception {
    String str = tm.getPayload();
    String username = ...;

    // regist user
    if (!map_id.get(wss.getId())) {
        map_id.put(wss.getId(), username);
        map_id.put(username, …
Run Code Online (Sandbox Code Playgroud)

java spring

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

spring ×1