Libraryless. Click here for Pure Java version (3984L/30K/85K).
1 | !7 |
2 | |
3 | p {
|
4 | serveHttpWithWebsockets(8888, func(NanoHTTPD.IHTTPSession handshake) {
|
5 | ret new WebSocket(handshake) {
|
6 | protected void onPong(WebSocketFrame pongFrame) { print("pong"); }
|
7 | protected void onMessage(WebSocketFrame messageFrame) { print("msg: " + messageFrame.getTextPayload()); }
|
8 | protected void onClose(WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) { print("close"); }
|
9 | protected void onException(IOException e) { printStackTrace(e); }
|
10 | }; |
11 | }); |
12 | } |
13 | |
14 | html {
|
15 | ret "JavaScript doing its magic..." |
16 | + hjavascript([[ |
17 | var exampleSocket = new WebSocket("ws://localhost:8888/");
|
18 | exampleSocket.onopen = function(event) {
|
19 | exampleSocket.send("Here is an important message!");
|
20 | exampleSocket.close(); |
21 | }; |
22 | ]]); |
23 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1009198 |
| Snippet name: | HTTP Server With WebSockets [WORKS] |
| Eternal ID of this version: | #1009198/16 |
| Text MD5: | 07b9852e0290d479e001a3eb228f19f4 |
| Transpilation MD5: | b62fbaa410e6b160be417d4a549fa941 |
| Author: | stefan |
| Category: | javax / networking |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-07-16 16:33:05 |
| Source code size: | 800 bytes / 23 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 771 / 983 |
| Version history: | 15 change(s) |
| Referenced in: | [show references] |