ws:send($msg, $ids) sends only to the explicitly addressed clients. @throws Exception exception
()
| 100 | * @throws Exception exception |
| 101 | */ |
| 102 | @Test public void send() throws Exception { |
| 103 | // connect handler sends the new client its own id (target=self only, to avoid noise) |
| 104 | register( |
| 105 | "declare %ws:connect('/p') function m:c() { ws:send(ws:id(), ws:id()) };" + |
| 106 | "declare %ws:message('/p', '{$m}') function m:msg($m) {" + |
| 107 | " ws:send('target:' || ws:id(), tokenize($m, ','))" + |
| 108 | "};"); |
| 109 | |
| 110 | final Listener la = new Listener(); |
| 111 | final Listener lb = new Listener(); |
| 112 | final Listener lc = new Listener(); |
| 113 | final java.net.http.WebSocket wsa = connect("/p", la); |
| 114 | final String aid = la.pollText(); |
| 115 | final java.net.http.WebSocket wsb = connect("/p", lb); |
| 116 | final String bid = lb.pollText(); |
| 117 | final java.net.http.WebSocket wsc = connect("/p", lc); |
| 118 | final String cid = lc.pollText(); |
| 119 | |
| 120 | try { |
| 121 | // a tells server to send to b and c only |
| 122 | wsa.sendText(bid + ',' + cid, true).get(5, TimeUnit.SECONDS); |
| 123 | assertEquals("target:" + aid, lb.pollText()); |
| 124 | assertEquals("target:" + aid, lc.pollText()); |
| 125 | Thread.sleep(200); |
| 126 | assertNull(la.texts.poll(), "Sender (a) should not have received its own send()."); |
| 127 | } finally { |
| 128 | close(wsa); |
| 129 | close(wsb); |
| 130 | close(wsc); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * {@code ws:set} / {@code ws:get} / {@code ws:delete} round-trip on the |