How to run grpc on ipv4 only

Viewed 756

I'm going to run a grpc server on IPv4 address like this:

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
protoc_pb2_grpc.add_ProtocServicer_to_server(StockProtocServicer(), server)
server.add_insecure_port('0.0.0.0:5000')
server.start()

But it it's listening to IPv6. Here is the output for lsof -i -n -P | grep 5000:

python    7302             dev    6u  IPv6 224100      0t0  TCP *:5000 (LISTEN)

I've tested listening on IPv6 to see what happens, like this:

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
protoc_pb2_grpc.add_ProtocServicer_to_server(UserProtocServicer(), server)
server.add_insecure_port('[::]:5000')
server.start()

but the result was the same:

python    7366             dev    6u  IPv6 225782      0t0  TCP *:5000 (LISTEN)

I also tried to use the actual IP address instead of 0.0.0.0:

python    7392             dev    6u  IPv6 226111      0t0  TCP 192.168.1.23:5000 (LISTEN)

Although I can use the server's IPv4 address on my client, I want to run the server only on IPv4. How can I do that?

0 Answers
Related