Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Basically the strategy to take is to have the server register itself as the root object. When the client connects to the server, it sends the server a connection message (defined by the server's protocol you create) that allows the server to register that client in order to send messages to it in the future. This could be as simple as adding the client to an array; no special run loops or threads should be needed. </p> <p>Here's a quick example to communicate across processes, from a test app I wrote back when I was learning DO for the first time. Once the setup is done you can add code to make the server send messages to one or more objects in the <code>_clients</code> array based on any event you'd like, including setting up a timer for a rough game loop.</p> <p><strong>Server:</strong></p> <pre><code>- (void)registerClient:(byref Client *)client; { [_clients addObject:client]; } - (void)awakeFromNib; { _clients = [[NSMutableArray alloc] init]; [[NSConnection defaultConnection] setRootObject:self]; if ( [[NSConnection defaultConnection] registerName:@"server"] == NO ) { // error code! } } </code></pre> <p><strong>Client:</strong></p> <pre><code>- (void)awakeFromNib; { id theProxy; theProxy = [[NSConnection rootProxyForConnectionWithRegisteredName:@"server" host:nil] retain]; [theProxy setProtocolForProxy:@protocol(ServerP)]; if ( theProxy == nil ) // error code! [theProxy registerClient:self]; } </code></pre> <p>Keep in mind that there are a lot of "gotchas" in distributed objects! Start simple, even if it means developing a rough prototype of your game idea first.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload