the newbie coder
the newbie coder

Reputation: 682

Setting port for gRPC server

From my understanding, gRPC's protocol is http2 on top of TCP. Therefore, the maximum port that can be assigned is 65535, right? But it seems like if I set the server address to be something like "0.0.0.0:70040" which is out of the range, it is still working fine and the gRPC client is able to connect and communicate with the gRPC server. May I know what does this actually mean? Thank you.

builder.AddListeningPort("0.0.0.0:70040", grpc::InsecureServerCredentials());

Upvotes: 1

Views: 14926

Answers (1)

DazWilkin
DazWilkin

Reputation: 40251

I suspect the issue is that, the use of strings for the endpoint address limits the ability of the compiler to validate the unsigned 16-bit port address.

70040 by my early morning calculation is 10001000110011000 which is 17-bits. Ports must be 16-bits so one of these bits will be getting dropped, probably the most significant one (1).

Dropping that, yields 1000110011000 which corresponds to 4504 and it's likely the actual port that's being used.

You could try running the server on 70040 and connect to it from the the client using 4504.

Upvotes: 7

Related Questions