Re: [rpyc] getting IP addresses of the TCP connection from within method

568 views
Skip to first unread message

Tomer Filiba

unread,
Mar 8, 2013, 11:42:20 AM3/8/13
to rpyc
see the "endpoints" attribute of the connection dictionary:


-tomer

-----------------------------------------------------------------
    
Tomer Filiba 
tomerfiliba.com        


On Fri, Mar 8, 2013 at 5:48 PM, Alexandre Bezroutchko <a...@gremwell.com> wrote:
Hello,

I would like to get an IP addresses of the client (and preferably the server) from within the method. Is it possible? Ultimately I would like the following piece of code to work:

#!/usr/bin/python

import rpyc
import config

class Server(rpyc.Service):
    def exposed_get_addrs(self):
    """ Return a tuple of client and server addresses """
    client_addr = ...
    server_addr = ...
    return (client_addr, server_addr)

if __name__ == "__main__":
    from rpyc.utils.server import ThreadedServer
    t = ThreadedServer(Server, port = config.PORT)
    t.start()


If I could get hold of the socket handle, I could use getsockname/addr methods, but how to get the socket? I browsed through the sources, and found that the socket seems to sit in Stream, Stream is in Channel, but it is not obvious for me how to get channel from inside of the method.

Best regards,
Alex

--
 
---
You received this message because you are subscribed to the Google Groups "rpyc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rpyc+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tomer Filiba

unread,
Mar 8, 2013, 11:43:08 AM3/8/13
to rpyc

-----------------------------------------------------------------
    
Tomer Filiba 
tomerfiliba.com        


Message has been deleted

Robert Nowotny

unread,
Oct 5, 2014, 4:53:37 PM10/5/14
to rp...@googlegroups.com
here the code : 

    def exposed_getConnectionInformation(self):
        s_ConnectionID=self._conn._config['connid']
        s_Credentials=self._conn._config['credentials']
        s_HostAdress, s_HostPort=self._conn._config['endpoints'][0]
        s_ClientAdress, s_ClientPort=self._conn._config['endpoints'][1]
        return(s_ConnectionID,s_Credentials,s_HostAdress,s_HostPort,s_ClientAdress,s_ClientPort)

yours sincerely
Robert


Reply all
Reply to author
Forward
0 new messages