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

Knowing ip address of client #137

Open
adhisimon opened this issue Oct 26, 2016 · 5 comments
Open

Knowing ip address of client #137

adhisimon opened this issue Oct 26, 2016 · 5 comments

Comments

@adhisimon
Copy link

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.

@mbush92
Copy link

mbush92 commented Oct 30, 2016

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:

let serverOptions = {
    host:'192.168.1.101',
    port: 6968,
   }
let server = xmlrpc.createServer(serverOptions)
server.httpServer.on('request', (req)=>{
  let incomingIPAddr = req.connection.remoteAddress
  console.log('IP ADDRESS:', incomingIPAddr)
})

Yields on the console log:

IP ADDRESS 192.168.56.101

@adhisimon
Copy link
Author

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
        .....
    })

@mbush92
Copy link

mbush92 commented Oct 31, 2016

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

@adhisimon
Copy link
Author

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.

@mbush92
Copy link

mbush92 commented Nov 1, 2016

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.

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