Remote Procedure Call (RPC) in C++: Can multiple Clients listen to one server when endpoint is hard coded?

2k views Asked by At

I'm writing a simple server-client using MIDL and RPC to allow file transferring. It works when endpoint is hard coded as follow:

server side

status = RpcServerUseProtseqEp(  
    reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), 
    RPC_C_PROTSEQ_MAX_REQS_DEFAULT,                   
    reinterpret_cast<unsigned char*>("8888"),         
    NULL);                                            

Client Side

status = RpcStringBindingCompose(NULL,
    "ncacn_ip_tcp",
    (RPC_CSTR)"127.0.0.1", 
    "8888",
    NULL,
    NULL);

I'm wondering if multiple clients are able to connect to one server when endpoint is hard coded? As we know that in socket programming using TCP protocol, two application cannot connect to a single port at one time. However, the MSDN reference says that RPC server process uses a first-in, first-out call queue to handle requests.

If it is unable to receive multiple requests from clients, is there a way to set an endpoint pool? Thank you.

1

There are 1 answers

0
rustyx On BEST ANSWER

You're confusing the terminology here.

The server is listening on a TCP port. That means it binds to the port and starts the accept loop on it. Every time that a new client connects to this port, the accept function establishes a TCP connection with that client, and goes back to listening on the port.

The server application is either a multi-threaded or an asynchronous application that handles multiple actions simultaneously: listening for new clients, communicating with each connected client and performing the actual work.

A typical RPC server would look something like

status = RpcServerUseProtseqEp(pszProtocolSequence,
                               RPC_C_LISTEN_MAX_CALLS_DEFAULT,
                               pszEndpoint,
                               pszSecurity); 

if (status) exit(status);

status = RpcServerRegisterIf(my_rpc_interface_spec,  
                             NULL,   
                             NULL); 

if (status) exit(status);

status = RpcServerListen(cMinCalls,
                         RPC_C_LISTEN_MAX_CALLS_DEFAULT,
                         0);

if (status) exit(status);

The RpcServerListen call would block forever, start cMinCalls worker threads and perform the accept loop, accepting the connections and handling the requests in up to cMinCalls parallel threads.