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

!7

lib 1009220 // websocket

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_10;
import org.java_websocket.handshake.ServerHandshake;

p {
  WebSocketClient mWs = new WebSocketClient(new URI("ws://localhost:8888/")/*, new Draft_10*/) {
    @Override
    public void onMessage( String message ) {
      print("message from server: " + message);
    }

    @Override
    public void onOpen( ServerHandshake handshake ) {
        System.out.println( "opened connection" );
    }

    @Override
    public void onClose( int code, String reason, boolean remote ) {
        System.out.println( "closed connection" );
    }

    @Override
    public void onError( Exception ex ) {
        ex.printStackTrace();
    }
  };
  
  //open websocket
  //mWs.connect();
  assertTrue("connect", mWs.connectBlocking());
  String message = "hallo";
  //send message
  mWs.send(message);
  mWs.close();
}

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: 626 / 749
Version history: 6 change(s)
Referenced in: #1014686 - WebSocket Client Test 2 (OK, but no auto-reconnect)