【发布时间】:2015-07-06 20:08:45
【问题描述】:
我有一个 netty 套接字客户端。从那个客户端,我必须首先发送登录名和密码,然后等待服务器和 IF 的回答,只有成功,我才能继续工作。有没有办法以同步方式运行登录方法?这是我的客户代码:
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(workerGroup)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.handler(new TRSClientInterfaceInitializer());
Channel ch = bootstrap.connect(host, port).sync().channel();
ChannelFuture lastWriteFuture = null;
lastWriteFuture = ch.writeAndFlush("username-password" + "\n");
ch.closeFuture().sync();
if (lastWriteFuture != null) {
lastWriteFuture.sync();
}
【问题讨论】:
-
你所说的成功究竟是什么意思?发送消息成功还是登录成功?