当前位置: 首页>>代码示例>>Java>>正文


Java NetClient.connect方法代码示例

本文整理汇总了Java中io.vertx.core.net.NetClient.connect方法的典型用法代码示例。如果您正苦于以下问题:Java NetClient.connect方法的具体用法?Java NetClient.connect怎么用?Java NetClient.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.net.NetClient的用法示例。


在下文中一共展示了NetClient.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Override
public void start(Handler<AsyncResult<Void>> startFuture) {
  if (port > 0) {
    // fail if port is already in use
    NetClientOptions options = new NetClientOptions().setConnectTimeout(200);
    NetClient c = vertx.createNetClient(options);
    c.connect(port, "localhost", res -> {
      if (res.succeeded()) {
        NetSocket socket = res.result();
        socket.close();
        startFuture.handle(Future.failedFuture("port " + port + " already in use"));
      } else {
        start2(startFuture);
      }
    });
  } else {
    start2(startFuture);
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:20,代码来源:ProcessModuleHandle.java

示例2: waitPortToClose

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
private void waitPortToClose(Handler<AsyncResult<Void>> stopFuture, int iter) {
  if (port > 0) {
    // fail if port is already in use
    NetClientOptions options = new NetClientOptions().setConnectTimeout(50);
    NetClient c = vertx.createNetClient(options);
    c.connect(port, "localhost", res -> {
      if (res.succeeded()) {
        NetSocket socket = res.result();
        socket.close();
        if (iter > 0) {
          vertx.setTimer(100, x -> waitPortToClose(stopFuture, iter - 1));
        } else {
          stopFuture.handle(Future.failedFuture("port " + port + " not shut down"));
        }
      } else {
        stopFuture.handle(Future.succeededFuture());
      }
    });
  } else {
    stopFuture.handle(Future.succeededFuture());
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:23,代码来源:ProcessModuleHandle.java

示例3: noConnectSent

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void noConnectSent(TestContext context) {

  NetClient client = this.vertx.createNetClient();
  Async async = context.async();

  client.connect(MQTT_SERVER_PORT, MQTT_SERVER_HOST, done -> {

    if (done.succeeded()) {

      done.result().closeHandler(v -> {
        log.info("No CONNECT sent in " + MQTT_TIMEOUT_ON_CONNECT + " secs. Closing connection.");
        async.complete();
      });

    } else {
      context.fail();
    }
  });

  // check that the async is completed (so connection was closed by server) in
  // the specified timeout (+500 ms just for being sure)
  async.await(500 + MQTT_TIMEOUT_ON_CONNECT * 1000);
  if (!async.isCompleted())
    context.fail();
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:27,代码来源:MqttServerConnectionTest.java

示例4: testSendMessageWithReplyBacktrack

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void testSendMessageWithReplyBacktrack(TestContext context) {
  // Send a request and get a response
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      JsonObject frame = parse.result();
      context.assertNotEquals("err", frame.getString("type"));
      context.assertEquals("Hello vert.x", frame.getJsonObject("body").getString("value"));
      client.close();
      async.complete();
    });

    socket.handler(parser);

    FrameHelper.sendFrame("send", "hello", "#backtrack", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:26,代码来源:TcpEventBusBridgeInteropTest.java

示例5: testSendMessageWithDuplicateReplyID

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void testSendMessageWithDuplicateReplyID(TestContext context) {
  // replies must always return to the same origin

  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    vertx.eventBus().consumer("third-party-receiver", msg -> context.fail());

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      client.close();
      async.complete();
    });

    socket.handler(parser);


    FrameHelper.sendFrame("send", "hello", "third-party-receiver", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:27,代码来源:TcpEventBusBridgeInteropTest.java

示例6: testSendVoidMessage

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void testSendVoidMessage(TestContext context) {
  // Send a request and get a response
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  vertx.eventBus().consumer("test", (Message<JsonObject> msg) -> {
    client.close();
    async.complete();
  });

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    FrameHelper.sendFrame("send", "test", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:20,代码来源:TcpEventBusBridgeTest.java

示例7: testSendsFromOtherSideOfBridge

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void testSendsFromOtherSideOfBridge(TestContext context) {
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      JsonObject frame = parse.result();
      context.assertNotEquals("err", frame.getString("type"));
      context.assertEquals(true, frame.getBoolean("send"));
      context.assertEquals("hi", frame.getJsonObject("body").getString("value"));
      client.close();
      async.complete();
    });

    socket.handler(parser);

    FrameHelper.sendFrame("register", "ping", null, socket);
  });

}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:27,代码来源:TcpEventBusBridgeTest.java

示例8: testSendMessageWithReplyBacktrack

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void testSendMessageWithReplyBacktrack(TestContext context) {
  // Send a request and get a response
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      JsonObject frame = parse.result();
      context.assertNotEquals("err", frame.getString("type"));
      context.assertEquals(true, frame.getBoolean("send"));
      context.assertEquals("Hello vert.x", frame.getJsonObject("body").getString("value"));
      client.close();
      async.complete();
    });

    socket.handler(parser);

    FrameHelper.sendFrame("send", "hello", "#backtrack", new JsonObject().put("value", "vert.x"), socket);
  });
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:27,代码来源:TcpEventBusBridgeTest.java

示例9: testSendPing

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void testSendPing(TestContext context) {
  NetClient client = vertx.createNetClient();
  final Async async = context.async();
  eventHandler = event -> {
    if (event.type() == BridgeEventType.SOCKET_PING) {
      async.complete();
    }
  };
  client.connect(7000, "localhost", context.asyncAssertSuccess(socket -> {
    socket.handler(buff -> {

    });
    FrameHelper.sendFrame("register", "echo", null, socket);
    FrameHelper.sendFrame("ping", socket);
  }));
}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:18,代码来源:TcpEventBusBridgeTest.java

示例10: check

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Override
public Future<Result> check() {
    Future<Result> future = Future.future();

    NetClientOptions options = new NetClientOptions().setConnectTimeout(500);
    NetClient client = vertx.createNetClient(options);

    client.connect(port, host, res -> {
        if (res.succeeded()) {
            future.complete(Result.healthy());
        } else {
            future.complete(Result.unhealthy(res.cause()));
        }

        client.close();
    });

    return future;
}
 
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:20,代码来源:ManagementApiProbe.java

示例11: check

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Override
public CompletableFuture<Result> check() {
    VertxCompletableFuture<Result> result = new VertxCompletableFuture<>(vertx);

    NetClientOptions options = new NetClientOptions().setConnectTimeout(500);
    NetClient client = vertx.createNetClient(options);

    client.connect(port, host, res -> {
        if (res.succeeded()) {
            result.complete(Result.healthy());
        } else {
            result.complete(Result.unhealthy(res.cause()));
        }

        client.close();
    });

    return result;
}
 
开发者ID:gravitee-io,项目名称:gravitee-gateway,代码行数:20,代码来源:GatewayProbe.java

示例12: execute

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Override
public GremlinClient execute(String json, Handler<Buffer> handler) {
    NetClient netClient = vertx.createNetClient();
    netClient.connect(port, host, res -> {
        if (res.succeeded()) {
            NetSocket socket = res.result();
            socket.write(json).handler(handler);
        }
    });
    return this;
}
 
开发者ID:openmg,项目名称:vertx-gremlin,代码行数:12,代码来源:GremlinClientImp.java

示例13: tryConnect

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
private void tryConnect(Handler<AsyncResult<Void>> startFuture, int count) {
  NetClientOptions options = new NetClientOptions().setConnectTimeout(MILLISECONDS);
  NetClient c = vertx.createNetClient(options);
  c.connect(port, "localhost", res -> {
    if (res.succeeded()) {
      logger.info("Connected to service at port " + port + " count " + count);
      NetSocket socket = res.result();
      socket.close();
      try {
        p.getErrorStream().close();
      } catch (Exception e) {
        logger.error("Closing streams failed: " + e);
      }
      startFuture.handle(Future.succeededFuture());
    } else if (!p.isAlive() && p.exitValue() != 0) {
      logger.warn("Service returned with exit code " + p.exitValue());
      startFuture.handle(Future.failedFuture("Service returned with exit code "
        + p.exitValue()));
    } else if (count < maxIterations) {
      vertx.setTimer((long) (count + 1) * MILLISECONDS,
        id -> tryConnect(startFuture, count + 1));
    } else {
      startFuture.handle(Future.failedFuture("Deployment failed. "
        + "Could not connect to port " + port + ": " + res.cause().getMessage()));
    }
  });
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:28,代码来源:ProcessModuleHandle.java

示例14: connectToRemote

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
private void connectToRemote(String addr, int port) {
    // 5s timeout.
    NetClientOptions options = new NetClientOptions().setConnectTimeout(5000);
    NetClient client = mVertx.createNetClient(options);
    client.connect(port, addr, res -> {  // connect handler
        if (!res.succeeded()) {
            log.error("Failed to connect " + addr + ":" + port + ". Caused by " + res.cause().getMessage());
            destory();
            return;
        }
        mTargetSocket = res.result();
        setFinishHandler(mTargetSocket);
        mTargetSocket.handler(buffer -> { // remote socket data handler
            try {
                byte [] data = buffer.getBytes();
                byte [] encryptData = mCrypto.encrypt(data, data.length);
                flowControl(mClientSocket, mTargetSocket);
                mClientSocket.write(Buffer.buffer(encryptData));
            }catch(CryptoException e){
                log.error("Catch exception", e);
                destory();
            }
        });
        if (mBufferQueue.length() > 0) {
            handleStageData();
        }
    });
}
 
开发者ID:Bestoa,项目名称:shadowsocks-vertx,代码行数:29,代码来源:ServerHandler.java

示例15: testRegister

import io.vertx.core.net.NetClient; //导入方法依赖的package包/类
@Test
public void testRegister(TestContext context) {
  // Send a request and get a response
  NetClient client = vertx.createNetClient();
  final Async async = context.async();

  client.connect(7000, "localhost", conn -> {
    context.assertFalse(conn.failed());

    NetSocket socket = conn.result();

    // 1 reply will arrive
    // MESSAGE for echo
    final FrameParser parser = new FrameParser(parse -> {
      context.assertTrue(parse.succeeded());
      JsonObject frame = parse.result();

      context.assertNotEquals("err", frame.getString("type"));
      context.assertEquals("Vert.x", frame.getJsonObject("body").getString("value"));
      client.close();
      async.complete();
    });

    socket.handler(parser);

    FrameHelper.sendFrame("register", "echo", null, socket);

    // now try to publish a message so it gets delivered both to the consumer registred on the startup and to this
    // remote consumer

    FrameHelper.sendFrame("publish", "echo", new JsonObject().put("value", "Vert.x"), socket);
  });

}
 
开发者ID:vert-x3,项目名称:vertx-tcp-eventbus-bridge,代码行数:35,代码来源:TcpEventBusBridgeInteropTest.java


注:本文中的io.vertx.core.net.NetClient.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。