Package org.java_websocket.client

Examples of org.java_websocket.client.WebSocketClient


    //for legacy code, to be able pass connection only
    private RmiProxy rmiProxy;

    public Connection(final String username, URI uri, MessageListener _listener) {
        this.listener = _listener;
        ws = new WebSocketClient(uri) {
            @Override
            public void onClose(int code, String reason, boolean remote) {
                listener.onWebsocketClose(code, reason, remote);
            }
View Full Code Here


**/
public class FragmentedFramesExample {
  public static void main( String[] args ) throws URISyntaxException , IOException , InterruptedException {
    // WebSocketImpl.DEBUG = true; // will give extra output

    WebSocketClient websocket = new ExampleClient( new URI( "ws://localhost:8887" ), new Draft_17() ); // Draft_17 is implementation of rfc6455
    if( !websocket.connectBlocking() ) {
      System.err.println( "Could not connect to the server." );
      return;
    }

    System.out.println( "This example shows how to send fragmented(continuous) messages." );

    BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );
    while ( websocket.isOpen() ) {
      System.out.println( "Please type in a loooooong line(which then will be send in 2 byte fragments):" );
      String longline = stdin.readLine();
      ByteBuffer longelinebuffer = ByteBuffer.wrap( longline.getBytes() );
      longelinebuffer.rewind();

      for( int position = 2 ; ; position += 2 ) {
        if( position < longelinebuffer.capacity() ) {
          longelinebuffer.limit( position );
          websocket.sendFragmentedFrame( Opcode.TEXT, longelinebuffer, false );// when sending binary data one should use Opcode.BINARY
          assert ( longelinebuffer.remaining() == 0 );
          // after calling sendFragmentedFrame one may reuse the buffer given to the method immediately
        } else {
          longelinebuffer.limit( longelinebuffer.capacity() );
          websocket.sendFragmentedFrame( Opcode.TEXT, longelinebuffer, true );// sending the last frame
          break;
        }

      }
      System.out.println( "You can not type in the next long message or press Ctr-C to exit." );
View Full Code Here

    } catch ( URISyntaxException e ) {
      e.printStackTrace();
    }
    int totalclients = clients.getValue();
    while ( websockets.size() < totalclients ) {
      WebSocketClient cl = new ExampleClient( uri ) {
        @Override
        public void onClose( int code, String reason, boolean remote ) {
          System.out.println( "Closed duo " + code + " " + reason );
          clients.setValue( websockets.size() );
          websockets.remove( this );
        }
      };

      cl.connect();
      clients.setValue( websockets.size() );
      websockets.add( cl );
      Thread.sleep( joinrate.getValue() );
    }
    while ( websockets.size() > clients.getValue() ) {
View Full Code Here

      }

    } else if( e.getSource() == connect ) {
      try {
        // cc = new ChatClient(new URI(uriField.getText()), area, ( Draft ) draft.getSelectedItem() );
        cc = new WebSocketClient( new URI( uriField.getText() ), (Draft) draft.getSelectedItem() ) {

          @Override
          public void onMessage( String message ) {
            ta.append( "got: " + message + "\n" );
            ta.setCaretPosition( ta.getDocument().getLength() );
View Full Code Here

TOP

Related Classes of org.java_websocket.client.WebSocketClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.