erpc icon indicating copy to clipboard operation
erpc copied to clipboard

single TCP server & multiple TCP clients supported?

Open saimukund opened this issue 4 years ago • 7 comments

Hi,

Is it possible to have single tcp server running and multiple clients calling rpc service?

talserver is my erpc server and taltest is the client which i am starting from a shell script as below.

I am getting below error when i try it.

/data/t1.sh 0 &

/data/t2.sh 0 &

/data/t1.sh 1 &

taltest: /home/saimukunds/erpc_develop/erpc/erpc_c/setup/erpc_client_setup.cpp:44: void erpc_client_init(erpc_transport_t, erpc_mbf_t): Assertion `transport' failed.

taltest: /home/saimukunds/erpc_develop/erpc/erpc_c/setup/erpc_client_setup.cpp:44: void erpc_client_init(erpc_transport_t, erpc_mbf_t): Assertion `transport' failed. Connection closed by foreign host.

I am trying to run the client in while loop to call server API. I created 3 instances of client here.

saimukund avatar Oct 14 '21 14:10 saimukund

Hi eRPC user. Thank you for your interest and welcome. We hope you will enjoy this framework well.

github-actions[bot] avatar Oct 14 '21 14:10 github-actions[bot]

Hi @saimukund, please take a look to #174

MichalPrincNXP avatar Oct 15 '21 13:10 MichalPrincNXP

in the latest code, The tcp server exit immediately after communication with one client. While concurrent clients are not supported, server should be able to handle one client after other. isn't it?

In erpc_status_t TCPTransport::underlyingReceive(uint8_t *data, uint32_t size) if we comment below two lines, server can run in while(true) and serve multiple clients(one after other), but socket fd leak happens here. Is there a clean way to ensure server is always running?

erpc_status_t TCPTransport::underlyingReceive(uint8_t *data, uint32_t size) {
// code
                // close socket, not server
                close(false);
                status = kErpcStatus_ConnectionClosed;
//code
}

saimukund avatar Oct 18 '21 10:10 saimukund

while (1)  {
erpc_server_run();
} 

It resolved issue for clients connecting serially.

saimukund avatar Oct 18 '21 13:10 saimukund

There seems to be a timing issue with this approach when a client request is send when server not yet open socket in "erpc_server_run()-> serverThread" this is leading to abort in client.

saimukund avatar Oct 19 '21 11:10 saimukund

@MichalPrincNXP After every client - server transaction, tcp transport server is getting exit. I added while loop in my server to ensure server process always is alive and erpc server will receive message from clients continuously. But some times client aborts if server not ready.

while (1) 
{ 
    erpc_server_run(); 
}

Can you point when is server actually "ready" to receive client connection when we call erpc_server_run() ? I can try to synchronize the server with client using (named) semaphores.

saimukund avatar Oct 21 '21 13:10 saimukund

Hello @saimukund , I think we have to focus on the correct behavior of the TCP transport layer and the erpc infrastructure first, instead of trying to workaround it by failing server re-running. Unfortunately there are currently no resources for this task but this has been identified as priority issue for the future. I am sorry.

MichalPrincNXP avatar Oct 26 '21 12:10 MichalPrincNXP