EmbeddedRPC / erpc

Embedded RPC
https://github.com/EmbeddedRPC/erpc/wiki
BSD 3-Clause "New" or "Revised" License
679 stars 196 forks source link

single TCP server & multiple TCP clients supported? #210

Open saimukund opened 2 years ago

saimukund commented 2 years ago

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.

github-actions[bot] commented 2 years ago

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

MichalPrincNXP commented 2 years ago

Hi @saimukund, please take a look to #174

saimukund commented 2 years ago

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 commented 2 years ago
while (1)  {
erpc_server_run();
} 

It resolved issue for clients connecting serially.

saimukund commented 2 years ago

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 commented 2 years ago

@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.

MichalPrincNXP commented 2 years ago

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.