-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Comments
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 |
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. |
Not sure I understand what you mean by this? What is the "obj" that you want to pass to the service? |
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. |
I'll try and whip something together, whenever I can find the time! |
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. |
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.
The text was updated successfully, but these errors were encountered: