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

39
LINES

< > BotCompany Repo | #1009221 // WebSocket Client Test [WORKS with #1009198]

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

Uses 113K of libraries. Click here for Pure Java version (453L/4K/12K).

1  
!7
2  
3  
lib 1009220 // websocket
4  
5  
import org.java_websocket.client.WebSocketClient;
6  
import org.java_websocket.drafts.Draft_10;
7  
import org.java_websocket.handshake.ServerHandshake;
8  
9  
p {
10  
  WebSocketClient mWs = new WebSocketClient(new URI("ws://localhost:8888/")/*, new Draft_10*/) {
11  
    @Override
12  
    public void onMessage( String message ) {
13  
      print("message from server: " + message);
14  
    }
15  
16  
    @Override
17  
    public void onOpen( ServerHandshake handshake ) {
18  
        System.out.println( "opened connection" );
19  
    }
20  
21  
    @Override
22  
    public void onClose( int code, String reason, boolean remote ) {
23  
        System.out.println( "closed connection" );
24  
    }
25  
26  
    @Override
27  
    public void onError( Exception ex ) {
28  
        ex.printStackTrace();
29  
    }
30  
  };
31  
  
32  
  //open websocket
33  
  //mWs.connect();
34  
  assertTrue("connect", mWs.connectBlocking());
35  
  String message = "hallo";
36  
  //send message
37  
  mWs.send(message);
38  
  mWs.close();
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, triorysbatvj, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009221
Snippet name: WebSocket Client Test [WORKS with #1009198]
Eternal ID of this version: #1009221/7
Text MD5: 840c17511791dc5fc5168d16346f6e65
Transpilation MD5: ac243c3fd9803cfc17461e9ef7417abe
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-17 03:28:34
Source code size: 966 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 516 / 635
Version history: 6 change(s)
Referenced in: [show references]