Hi,

you can get the ip-address of the client from the socket using
getpeername() if you need to identify the client.

Greetings
Ruediger

2012/2/26 Shivakumar GN <[email protected]>:
> Thanks.
>
> I was looking for means to identify client by IP or hostname so that
> some smarter functionality is possible on server.
> But the below solution is just about ok for me.
>
>
> On Thu, Feb 23, 2012 at 7:18 AM, Rüdiger Kessel
> <[email protected]> wrote:
>> Hi Shivakumar,
>>
>> if you use a threading server something like this will work:
>>
>> class MyService(rpyc.Service):
>>    _ClientID=0
>>    activeConnections=0
>>    LOCK=Thread.allocate_lock()
>>    def IncClientID(self):
>>        MyService.LOCK.acquire()
>>        MyService._ClientID+=1
>>        self._ClientID=MyService._ClientID
>>        MyService.LOCK.release()
>>    def on_connect(self):
>>        self.IncClientID()
>>        MyService.LOCK.acquire()
>>        MyService.activeConnections+=1
>>        self.writeaccess=MyService.activeConnections==1
>>        MyService.LOCK.release()
>>    def on_disconnect(self):
>>        MyService.LOCK.acquire()
>>        MyService.activeConnections-=1
>>        MyService.LOCK.release()
>>
>> If the client who has write access quits then none of the other get
>> write access. So this is not bullet prove but might work in your case.
>>
>> Rüdiger
>>
>>
>> 2012/2/23 Shivakumar GN <[email protected]>:
>>> Hi All,
>>>
>>> I am creating a rpyc server that provides services of "read" and "write" 
>>> nature.
>>> My need is - if multiple clients are connected, "write" must be
>>> possible by only one client while all other clients can have "read"
>>> access.
>>>
>>> Any suggestions on how to address this in a clean way?
>>>
>>> Seems like this requires:
>>>    - when a new client connects, being able to store client
>>> information in a manner accessible to sub-class of rpyc.Service
>>>    - providing a mechanism to request write access
>>>    - noting which client has write access
>>>    - on a per request basis, checking client information against the
>>> one client that has write access
>>>
>>> In rpyc, there is a clear separation between Server() which manages
>>> clients and connections and rpyc.Service() and the service layer is
>>> implemented.
>>> In my case, my rpyc.Service() based sub-class needs the client
>>> information to be tracked.
>>>
>>> thanks & best regards
>>> Shivakumar

Reply via email to