Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass client's IP to tcp server? #40

Open
SiriusKan opened this issue Jun 26, 2019 · 6 comments
Open

How to pass client's IP to tcp server? #40

SiriusKan opened this issue Jun 26, 2019 · 6 comments
Assignees

Comments

@SiriusKan
Copy link

Hi
First thanks for this great project!
What I want to know is, when use the tcp server mode, is there's a simple way to pass the client's IP to server such as the ExampleService in the README?

Thank you for any reply.

@joncol
Copy link
Owner

joncol commented Jun 26, 2019

Hi,

Just curious: why does the server need to know the client's IP?

If you look at https://github.com/joncol/jcon-cpp/blob/master/src/jcon/json_rpc_tcp_server.cpp#L70, you can see that the client's IP is logged. All connected client's are also saved in m_client_endpoints of that class. If you really need this, I could look into adding some better way of retrieving all connected clients' IP addresses... If that's what you need?

@SiriusKan
Copy link
Author

Thanks for your reply.

In some case, for example, a weather info RPC service, I want to let server response the request accoding to client's location, and I don't want client specify it's location in the request because I want to reduce the request data size, so I want to get client's IP in the server side such as in the ExampleService,

I've seen the code in json_rpc_tcp_server.cpp, I can get peerAddress from the endpoint, and now I can do it by insert a "cli_ip" data into the request param in the jsonRequestReceived() method in the json_rpc_server.cpp, but I think this is a "stupid" way, So I want know if there's a way to add a Interface to the JsonRpcServer class and pass the obj to ExampleService when calling the registerServices.

@joncol
Copy link
Owner

joncol commented Jun 26, 2019

So I want know if there's a way to add a Interface to the JsonRpcServer class and pass the obj to ExampleService when calling the registerServices.

Not sure I understand what you mean by this? What is the "obj" that you want to pass to the service?

@SiriusKan
Copy link
Author

Sorry for not said clearly.

I mean in json_rpc_server.cpp there's the endpoint object when dispatch request to ExampleServer, so I think it'll be better to pass a obj which contains the endpoint info to ExampleServer, for example, when call rpc_server->registerServices({ new ExampleService() }) , can we pass a such a obj pointer as the ExampleService's param ?

Thx again.

@joncol
Copy link
Owner

joncol commented Jun 28, 2019

I'll try and whip something together, whenever I can find the time!

@joncol joncol self-assigned this Jun 28, 2019
@joncol
Copy link
Owner

joncol commented Jul 3, 2019

Hi again,

If you have the opportunity, please take a look at #41, and see if this would work for you. It's a bit ugly solution perhaps, but it's simple and doesn't complicate the automatic service method lookup.

If you have any comments/feedback please get back to me and I'll try and take them into consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants