Drual
Drual

Reputation: 61

gRPC server to start on specific IP Address

how can I start gRPC server on some specific IP address? In every tutorial I found (used and tested) this:

    Server server = ServerBuilder.forPort(50051)
            .addService(new GreetServiceImpl().)
            .build();

    server.start();

But I need to specify not just port but full address: Something like this (non-existing code):

    Server server = ServerBuilder.forAddress(154.45.153.1)forPort(50051)
            .addService(new GreetServiceImpl().)
            .build();

    server.start();

Thanks

Upvotes: 0

Views: 2360

Answers (1)

Drual
Drual

Reputation: 61

So I found solution that works:

    Server server;

    SocketAddress address = new InetSocketAddress("10.0.150.116", 5085);
    server = NettyServerBuilder.forAddress(address).addService(new GreetServiceImpl()).build();

    server.start();

I do not know if there is some drawback with this approach.

Upvotes: 2

Related Questions