<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] # 1. 定時推送給所有人 實現步驟如下: **1. 啟動類上標注注解`@EnableScheduling`開啟定時服務** ```java @EnableScheduling @SpringBootApplication public class SocketApplication { public static void main(String[] args) { SpringApplication.run(SocketApplication.class, args); } } ``` **2. 方法上標注注解`@Scheduled`開始定時任務** ```java @Component @ServerEndpoint(value = "/v1/scheduled") public class ScheduledController { /** * 存儲每一個用戶的Session */ private final static Map<String, Session> onlineUsers = new HashMap<>(1); @OnOpen public void open(Session session) { //當用戶連接進來時存儲每一個用戶的Session onlineUsers.put(session.getId(), session); } //每3s鐘推送一次 @Scheduled(fixedRate = 3000) public void broadcastAllUsers() { for (Map.Entry<String, Session> entry : onlineUsers.entrySet()) { entry.getValue().getAsyncRemote().sendText("定時推送給所有人."); } } } ``` **3. 前端代碼** ```js var socket = null function connect() { if (socket == null) { socket = new WebSocket('ws://localhost:8090/v1/scheduled') socket.onmessage = (e) => { console.info(e.data) } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看