简体   繁体   中英

Bootstrap class doesn't have method (String host, int port)

Trying to make test client - server application and faced problem with this

Channel channel = bootstrap.connect(host, port).sync().channel();

Bootstrap's class doesn't have method connect with arg types String, int. How can i obtain channel?

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{

        }
    }
}

Took this sample from here https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/securechat/SecureChatClient.java

Thanks in advance

Its has... Be sure you depend on the correct netty version which is 4+.

See: https://github.com/netty/netty/blob/4.0/transport/src/main/java/io/netty/bootstrap/Bootstrap.java#L95

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM