Knowing ip address of client
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.
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
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.