Package com.barchart.udt

Examples of com.barchart.udt.SocketUDT


   *
   * @see {@link SocketChannelUDT}
   */
  @Override
  public SocketChannelUDT openSocketChannel() throws IOException {
    final SocketUDT socketUDT = new SocketUDT(type);
    return new SocketChannelUDT(this, socketUDT);
  }
View Full Code Here


  public SocketChannelUDT accept() throws IOException {
    try {

      begin();

      final SocketUDT clientUDT = socketUDT.accept();

      if (clientUDT == null) {

        return null;

      } else {

        return new SocketChannelUDT( //
            providerUDT(), //
            clientUDT, //
            clientUDT.isConnected() //
        );

      }
    } finally {
      end(true);
View Full Code Here

    // so we need to take that into account if you want
    // to limit wire speed
    final double maxBW = 50 * 0.93;
    log.info("Attempting to rate limit using custom CCC UDPBlast class");

    final SocketUDT serverSocket = new SocketUDT(TypeUDT.STREAM);
    final InetSocketAddress serverAddress = localSocketAddress();
    serverSocket.bind(serverAddress);
    serverSocket.listen(1);
    assertTrue(serverSocket.isBound());

    final SocketUDT clientSocket = new SocketUDT(TypeUDT.STREAM);

    clientSocket.setOption(OptionUDT.UDT_CC, new FactoryUDT<UDPBlast>(
        UDPBlast.class));

    final InetSocketAddress clientAddress = localSocketAddress();

    clientSocket.bind(clientAddress);
    clientSocket.setSoLinger(false, 0);
    assertTrue(clientSocket.isBound());

    clientSocket.connect(serverAddress);
    assertTrue(clientSocket.isConnected());

    final SocketUDT acceptSocket = serverSocket.accept();
    assertTrue(acceptSocket.isConnected());

    final Object obj = clientSocket.getOption(OptionUDT.UDT_CC);

    assertTrue("UDT_CC Object is of unexpected type",
        obj instanceof UDPBlast);

    final UDPBlast objCCC = (UDPBlast) obj;
    objCCC.setRate((int) maxBW);

    final byte[] data = new byte[65536];
    final long start = System.currentTimeMillis();
    long interval = System.currentTimeMillis();
    double maxMbs = -1;

    while ((System.currentTimeMillis() - start) < 15000) {

      clientSocket.send(data);
      acceptSocket.receive(data);

      if (System.currentTimeMillis() - interval > 1000) {

        interval = System.currentTimeMillis();

        clientSocket.updateMonitor(true);

        final MonitorUDT mon = clientSocket.monitor();

        log.info(String.format("Current Rate: %.2f Mbs",
            mon.mbpsSendRate()));

        maxMbs = mon.mbpsSendRate() * 0.93;

      }

    }

    // check we are within 10% of our desired rate
    assertTrue("Max bandwidth exceeded limit",
        maxMbs < (maxBW + (maxBW * 0.1)));

    clientSocket.close();
    acceptSocket.close();
    serverSocket.close();

  }
 
View Full Code Here

  @Override
  public void run() {

    try {

      final SocketUDT connectorSocket = socket.accept();

      final Runnable serviceTask = factory.newService(connectorSocket);

      executor.submit(serviceTask);
View Full Code Here

  }

  StreamServer(final TypeUDT type, final InetSocketAddress serverAddress,
      final ServiceFactory factory) throws Exception {

    super(new SocketUDT(type), UnitHelp.localSocketAddress(), serverAddress);

    this.factory = factory;

    this.executor = Executors.newCachedThreadPool();
View Full Code Here

  final ExecutorService executor;

  StreamClient(final TypeUDT type, final InetSocketAddress remoteAddress)
      throws Exception {

    super(new SocketUDT(type), UnitHelp.localSocketAddress(), remoteAddress);

    this.executor = Executors.newCachedThreadPool();

  }
View Full Code Here

    startThreadedServer(serverAddress, readStrategy);

    //

    final SocketUDT clientSocket = new SocketUDT(TypeUDT.STREAM);

    final InetSocketAddress clientAddress = UnitHelp.localSocketAddress();

    clientSocket.bind(clientAddress);
    assertTrue("Socket not bound!!", clientSocket.isBound());

    clientSocket.connect(serverAddress);
    assertTrue("Socket not connected!", clientSocket.isConnected());

    final InputStream socketIn = new NetInputStreamUDT(clientSocket);
    final OutputStream socketOut = new NetOutputStreamUDT(clientSocket);

    // Thread.sleep(1000);
View Full Code Here

      final ReadStrategy readStrategy, final AtomicBoolean readyToAccept)
      throws Exception {

    log.info("STARTED");

    final SocketUDT acceptorSocket = new SocketUDT(TypeUDT.STREAM);

    acceptorSocket.bind(serverAddress);
    assertTrue("Acceptor should be bound", acceptorSocket.isBound());

    acceptorSocket.listen(1);
    assertEquals("Acceptor should be listenin", acceptorSocket.status(),
        StatusUDT.LISTENING);

    readyToAccept.set(true);
    synchronized (readyToAccept) {
      readyToAccept.notifyAll();
    }
    final SocketUDT connectorSocket = acceptorSocket.accept();
    assertTrue(connectorSocket.isBound());
    assertTrue(connectorSocket.isConnected());

    echo(connectorSocket, readStrategy);

  }
View Full Code Here

  @Test
  public void blocking() throws Exception {

    final SelectorProviderUDT provider = SelectorProviderUDT.DATAGRAM;
    final SocketUDT socket = new SocketUDT(TypeUDT.DATAGRAM);
    final SocketChannelUDT channel = new SocketChannelUDT(provider, socket);

    assertTrue(socket.isOpen());
    assertTrue(channel.isOpen());

    assertTrue(socket.isBlocking());
    assertTrue(channel.isBlocking());

    channel.configureBlocking(false);

    assertFalse(socket.isBlocking());
    assertFalse(channel.isBlocking());

    channel.close();

    assertFalse(socket.isOpen());
    assertFalse(channel.isOpen());

  }
View Full Code Here

  @Override
  public void run() {

    try {

      final SocketUDT connectorSocket = socket.accept();

      final Runnable serviceTask = factory.newService(connectorSocket);

      executor.submit(serviceTask);
View Full Code Here

TOP

Related Classes of com.barchart.udt.SocketUDT

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.