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

41
LINES

< > BotCompany Repo | #1036596 // FlexWebSocketClient

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

Uses 211K of libraries. Click here for Pure Java version (10763L/61K).

1  
!include once #1015699 // websocket
2  
3  
sclass FlexWebSocketClient extends WebSocketClient {
4  
  *(URI uri) { super(uri); }
5  
  *(URI uri, SS httpHeaders) { super(uri, httpHeaders); }
6  
  
7  
  settable bool verbose;
8  
  
9  
  event opened(ServerHandshake handshake);
10  
  event gotMessage(S message);
11  
  event gotBinaryMessage(java.nio.ByteBuffer message);
12  
  event closed(CloseInfo info);
13  
  event error(Exception error);
14  
  
15  
  record noeq CloseInfo(int code, S reason, bool remote) {}
16  
17  
  public void onMessage(S s) {
18  
    if (verbose) print("WebSocket received: " + s);
19  
    gotMessage(s);
20  
  }
21  
  
22  
  public void onMessage(java.nio.ByteBuffer bytes) {
23  
    if (verbose) print("WebSocket received " + nBytes(bytes.remaining());
24  
    gotBinaryMessage(bytes);
25  
  }
26  
27  
  public void onOpen(ServerHandshake handshake) {
28  
    if (verbose) print("WebSocket opened");
29  
    opened(handshake);
30  
  }
31  
  
32  
  public void onClose(int code, S reason, bool remote) {
33  
    if (verbose) print("WebSocket closed, code " + code + ", reason: " + reason + ", remote: " + remote);
34  
    closed(new CloseInfo(code, reason, remote));
35  
  }
36  
  
37  
  public void onError(Exception e) {
38  
    printStackTrace(e);
39  
    error(e);
40  
  }
41  
}

Author comment

Began life as a copy of #1036022

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036596
Snippet name: FlexWebSocketClient
Eternal ID of this version: #1036596/6
Text MD5: b81e87e64ddb467b70ba105d0748b407
Transpilation MD5: e3a288c0f0881d41ee8d04af52171c7c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-09-03 13:58:25
Source code size: 1198 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 84 / 135
Version history: 5 change(s)
Referenced in: [show references]