-
Notifications
You must be signed in to change notification settings - Fork 150
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
Knowing ip address of client #137
Comments
Its possible to get the IP address of the client that is making the request. You simply need to access the underlying HTTP server object. If you access the request event you can get the remote IP address. For example:
Yields on the console log:
|
Thanks @mbush92 , but what I need is ip address of requester on method call. In the scope of method handler var serverOptions = {
port: 8081
};
var server = xmlrpc.createServer(serverOptions);
server.on('topUpReport', function (err, params, callback) {
// how can i get caller ip address here
.....
}) |
The server.httpServer.on event fires everytime someone makes a request to the RPC server. It's just an event from the httpServer that the RPC server is built in top of. There's no need to put it inside a method call, leave it outside the method and it will handle assigning the incoming requesters IP address to a global variable. We have several socket servers in other parts of our application and we use the same event to grab the incoming IP address to know how to retrieve data from our data store and serve it back |
Correct me if I'm wrong, but if I use server.httpServer.on outside method handler scope, I think it would not give me correct IP address if there are multiple requests near paralel at the same time from different IPs/clients. |
What we see on the socket side is that this is not the case, basically your methods only fire within an instance of the socket connection that belongs to a single requestor. They are making a socket connection, requesting what they want and then closing the connection when they are done. I have not hammered the RPC library we are building yet with multiple fast paced requestors but the TCP socket version of the library was handling dozens of requestors firing every second when we did some of our load testing. |
As XMLRPC server, I think it should be nice to have feature to know what is ip address of client who request. This feature needed for logging and access limit purpose.
The text was updated successfully, but these errors were encountered: