Problem In Accessing NSDistantobject

  • Hello All,

    I have created an application which uses Bonjour and Distributed
    Object (DO)to share files across the systems connected to the LAN, I
    have an issue with DO connection.
    That is I have created a NSConnection in a thread (say THREAD 1), and
    get the mProxy  (server vended object) using the call [connection
    rootproxy] in the same thread.But when try to use mProxy in another
    thread or in main thread, it raises an exception saying
    "NSDistantObject access attempted from another thread", documentation
    says this is due to my attempt to use mProxy which is created in
    another thread (THREAD 1).

    So what I have to do is keep running the THREAD 1 for long , and send
    all subsequent function calls to mProxy  in the  same thread(As I
    dont want to create separate thread and separate nsconnection for
    each function call to mProxy, instead use the same thread THREAD 1
    for all the time.).

    Can anybody please tell me, how to send request to mProxy (in my
    case) to execute remote methods using single thread which keeps
    running, or sending request for invoking  a method to already running
    thread or Any alternate way for my above problem (my be sample code).

    Please correct me if I am doing anything wrong in my above explained
    scenario.

    Thanks in advance.

    With Regards,
    Abu

    -----------------------------------------------
    Robosoft Technologies - Come home to Technology

    Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.
  • Hi Abu

    The standard way to use a distributed object is to create and use the
    proxy within your main thread, not to create a separate thread to do
    this. Which if I have understood you correctly is what you are trying
    to do. Simply use the following.

    //get connection
    myConnection = [[NSConnection connectionWithRegisteredName:@"myname"
    host:nil] retain];
    //set a sensible timeout
    [myConnection setReplyTimeout:10];
    //get proxy
    myProxy = [[guiConnection rootProxy] retain];

    ... some code ...

    id responce = [myProxy message];

    ... some more code..

    responce = [myProxy onotherMessage];

    Hope this helps

    Mike

    On 9 Jan 2008, at 04:40, Abdul Sattar wrote:

    > Hello All,
    >
    > I have created an application which uses Bonjour and Distributed
    > Object (DO)to share files across the systems connected to the LAN,
    > I have an issue with DO connection.
    > That is I have created a NSConnection in a thread (say THREAD 1),
    > and get the mProxy  (server vended object) using the call
    > [connection rootproxy] in the same thread.But when try to use
    > mProxy in another thread or in main thread, it raises an exception
    > saying "NSDistantObject access attempted from another thread",
    > documentation says this is due to my attempt to use mProxy which is
    > created in another thread (THREAD 1).
    >
    > So what I have to do is keep running the THREAD 1 for long , and
    > send all subsequent function calls to mProxy  in the  same thread
    > (As I dont want to create separate thread and separate nsconnection
    > for each function call to mProxy, instead use the same thread
    > THREAD 1  for all the time.).
    >
    > Can anybody please tell me, how to send request to mProxy (in my
    > case) to execute remote methods using single thread which keeps
    > running, or sending request for invoking  a method to already
    > running thread or Any alternate way for my above problem (my be
    > sample code).
    >
    > Please correct me if I am doing anything wrong in my above
    > explained scenario.
    >
    > Thanks in advance.
    >
    > With Regards,
    > Abu
    >
    >
    >
    > -----------------------------------------------
    > Robosoft Technologies - Come home to Technology
    >
    > Disclaimer: This email may contain confidential material. If you
    > were not an intended recipient, please notify the sender and delete
    > all copies. Emails to and from our network may be logged and
    > monitored. This email and its attachments are scanned for virus by
    > our scanners and are believed to be safe. However, no warranty is
    > given that this email is free of malicious content or virus.
  • On Jan 8, 2008, at 10:40 PM, Abdul Sattar wrote:

    > Can anybody please tell me, how to send request to mProxy (in my
    > case) to execute remote methods using single thread which keeps
    > running, or sending request for invoking  a method to already
    > running thread or Any alternate way for my above problem (my be
    > sample code).
    >
    > Please correct me if I am doing anything wrong in my above
    > explained scenario.

    I think you want the enableMultipleThreads method of the NSConnection
    instance.

    -Ken
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today