ws:emit($msg) sends a message to all connected clients (including the sender). @throws Exception exception
()
| 54 | * @throws Exception exception |
| 55 | */ |
| 56 | @Test public void emit() throws Exception { |
| 57 | register( |
| 58 | "declare %ws:message('/p', '{$m}') function m:msg($m) { ws:emit('all:' || $m) };"); |
| 59 | |
| 60 | final Listener la = new Listener(); |
| 61 | final Listener lb = new Listener(); |
| 62 | final java.net.http.WebSocket wsa = connect("/p", la); |
| 63 | final java.net.http.WebSocket wsb = connect("/p", lb); |
| 64 | try { |
| 65 | wsa.sendText("hi", true).get(5, TimeUnit.SECONDS); |
| 66 | assertEquals("all:hi", la.pollText()); |
| 67 | assertEquals("all:hi", lb.pollText()); |
| 68 | } finally { |
| 69 | close(wsa); |
| 70 | close(wsb); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * {@code ws:broadcast($msg)} sends to all clients except the sender. |