#include #include #include #include #include "MyConnection.h" #include "server.h" int main (int argc, char **argv) { CREATE_AUTORELEASE_POOL(pool); // [MyConnection setDebug: YES]; /* * Initialise connection */ puts ("*** Launch ***"); [MyConnection debug]; NSDistantObject *proxy = [MyConnection rootProxyForConnectionWithRegisteredName: @"MyObject" host: @"*"]; puts ("*** Connection ***"); [MyConnection debug]; /* * Send first message : ok */ printf ("*** Message ***\n%s\n", [[proxy message] cString]); /* * Change connection root object served on server */ printf ("Change root object ? [y/N] "); __fpurge (stdin); if (getchar() == 'y') { [proxy changeConnectionRootObject]; /* * Local object does not reflect this change */ printf ("*** Message2 ***\n%s\n", [[proxy message2] cString]); /* * Update our local proxy. This time we see the new served object. */ NSDistantObject *proxyB = [[proxy connectionForProxy] rootProxy]; printf ("*** Message2 - after proxy reinit ***\n%s\n", [[proxyB message2] cString]); } /* * Create new connection between the client and the server. */ printf ("Create connection ? [y/N] "); __fpurge (stdin); if (getchar() == 'y') { NSPort *receivePort2 = [GSTcpPort port]; NSPort *sendPort2 = [proxy createNewConnectionWithPort: receivePort2]; MyConnection *cnx2 = [MyConnection connectionWithReceivePort: receivePort2 sendPort: sendPort2]; puts ("*** Create connection ***"); printf ("new: "); [cnx2 debug]; [MyConnection debug]; NSDistantObject *proxy2 = [cnx2 rootProxy]; printf ("*** Message2 - new connection ***\n%s\n", [[proxy2 message2] cString]); } /* * Try to steal the last created connection */ printf ("Steal connection ? [y/N] "); __fpurge (stdin); if (getchar() == 'y') { NSPort *receivePort3 = [GSTcpPort port]; NSPort *sendPort3 = [proxy createNewConnectionWithPort: receivePort3]; MyConnection *cnx3 = [MyConnection connectionWithReceivePort: receivePort3 sendPort: sendPort3]; puts ("*** Steal connection ***"); printf ("new: "); [cnx3 debug]; [MyConnection debug]; NSDistantObject *proxy3 = [cnx3 rootProxy]; printf ("*** Message2 - stolen connection ***\n%s\n", [[proxy3 message2] cString]); } /* * Terminate program */ puts ("*** End ***"); [MyConnection debug]; RELEASE(pool); return EXIT_SUCCESS; }