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

27
LINES

< > BotCompany Repo | #1036322 // FlexWebSocket - subclass of WebSocket that has events

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13065L/81K).

sclass FlexWebSocket extends WebSocket {
  *(NanoHTTPD.IHTTPSession handshake) { super(handshake); }
  
  event gotMessage(WebSocketFrame messageFrame);
  event closed();

  public void send(WebSocketFrame frame) ctex {
    frame.write(out);
  }

  // This is for stupid shit like text decoding failures
  protected void onException(IOException e) { pcall_fail(e); }
  
  protected void onMessage(WebSocketFrame messageFrame) {
    gotMessage(messageFrame);
  }
  
  protected void onClose(WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) {
    closed();
  }
  
  public void close() ctex {
    pcall {
      close(WebSocketFrame.CloseCode.NormalClosure, "");
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036322
Snippet name: FlexWebSocket - subclass of WebSocket that has events
Eternal ID of this version: #1036322/3
Text MD5: ae39215f7def0c7417b233df40b5c943
Transpilation MD5: 4e80a173ee895fbf7b6b80fbef9a4363
Author: stefan
Category: javax / websockets
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-16 23:14:58
Source code size: 721 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 144 / 223
Version history: 2 change(s)
Referenced in: [show references]