尝试制作测试客户端 - 服务器应用程序并遇到此问题
Channel channel = bootstrap.connect(host, port).sync().channel();
Bootstrap的类没有与arg类型String,int连接的方法。我怎样才能获得频道?
public class ChatClient {
private final String host;
private final int port;
public static void main(String[] args) throws Exception{
new ChatClient("localhost", 8080).run();
}
public ChatClient(String host, int port) {
this.host = host;
this.port = port;
}
public void run() throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
try{
Bootstrap bootstrap = new Bootstrap()
.group(group)
.channel(NioSocketChannel.class)
.handler(new ChatClientInitializer());
Channel channel = bootstrap.connect(host, port).sync().channel();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while(true){
channel.write(in.readLine() + "\r\n");
}
}
finally{
}
}
}
取得此样本
提前致谢
答案 0 :(得分:0)
它有......确保你依赖4 +的正确netty版本。