小编use*_*996的帖子

Spring websocket超时设置

我正在使用Spring websocket支持.我的问题是如何设置websocket连接超时.现在连接几分钟后自动关闭.我希望永远不要关闭连接.

这是我的websocket处理程序:

public class MyHandler implements WebSocketHandler {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    class MyTimerTask extends TimerTask {
        private WebSocketSession session;
        public MyTimerTask(WebSocketSession session) {
            this.session = session;
        }

        @Override
        public void run() {
            try {
                String msg = ((int)(Math.random()*50)) + "";
                this.session.sendMessage(new TextMessage(msg.toString()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Autowired
    private UserDao userDao;

    @Autowired
    private JdbcDaoImpl jdbcDaoImpl;
    private Timer timer;

    @Override
    public void afterConnectionEstablished(WebSocketSession session)
            throws Exception {
        System.out.println("websocket????");
        timer = new Timer();
        timer.schedule(new MyTimerTask(session), …
Run Code Online (Sandbox Code Playgroud)

spring timeout websocket

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

标签 统计

spring ×1

timeout ×1

websocket ×1