Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1009198 // HTTP Server With WebSockets [WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (3984L/30K/85K).

!7

p {
  serveHttpWithWebsockets(8888, func(NanoHTTPD.IHTTPSession handshake) {
    ret new WebSocket(handshake) {
      protected void onPong(WebSocketFrame pongFrame) { print("pong"); }
      protected void onMessage(WebSocketFrame messageFrame) { print("msg: " + messageFrame.getTextPayload()); }
      protected void onClose(WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) { print("close"); }
      protected void onException(IOException e) { printStackTrace(e); }
    };
  });
}

html {
  ret "JavaScript doing its magic..."
    + hjavascript([[
  var exampleSocket = new WebSocket("ws://localhost:8888/");
  exampleSocket.onopen = function(event) {
    exampleSocket.send("Here is an important message!");
    exampleSocket.close();
  };
  ]]);
}

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: 463 / 613
Version history: 15 change(s)
Referenced in: [show references]