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).

1  
sclass FlexWebSocket extends WebSocket {
2  
  *(NanoHTTPD.IHTTPSession handshake) { super(handshake); }
3  
  
4  
  event gotMessage(WebSocketFrame messageFrame);
5  
  event closed();
6  
7  
  public void send(WebSocketFrame frame) ctex {
8  
    frame.write(out);
9  
  }
10  
11  
  // This is for stupid shit like text decoding failures
12  
  protected void onException(IOException e) { pcall_fail(e); }
13  
  
14  
  protected void onMessage(WebSocketFrame messageFrame) {
15  
    gotMessage(messageFrame);
16  
  }
17  
  
18  
  protected void onClose(WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) {
19  
    closed();
20  
  }
21  
  
22  
  public void close() ctex {
23  
    pcall {
24  
      close(WebSocketFrame.CloseCode.NormalClosure, "");
25  
    }
26  
  }
27  
}

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: 146 / 225
Version history: 2 change(s)
Referenced in: [show references]