1994-11-04 16:29:24 +00:00
|
|
|
#include "second-client.h"
|
1995-04-05 20:34:40 +00:00
|
|
|
#include <objects/String.h>
|
1996-03-06 14:47:46 +00:00
|
|
|
#include <objects/Notification.h>
|
|
|
|
#include <objects/Invocation.h>
|
|
|
|
|
|
|
|
id announce_new_connection (id notification)
|
|
|
|
{
|
|
|
|
id connection = [notification object];
|
|
|
|
#if 0
|
|
|
|
printf ("Created Connection 0x%x to %@\n",
|
|
|
|
(unsigned)connection, [[connection outPort] description]);
|
|
|
|
#endif
|
|
|
|
return nil;
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
id server;
|
|
|
|
id a1;
|
|
|
|
id remote_array;
|
|
|
|
char namebuf[16];
|
|
|
|
|
|
|
|
printf("Looking up server object on localhost with name `secondserver'\n");
|
1995-04-05 20:34:40 +00:00
|
|
|
server = [Connection rootProxyAtName:@"secondserver"];
|
1994-11-04 16:29:24 +00:00
|
|
|
printf("Found server.\n");
|
|
|
|
|
1996-03-06 14:47:46 +00:00
|
|
|
[NotificationDispatcher
|
|
|
|
addObserver: nil
|
|
|
|
invocation: [[[ObjectFunctionInvocation alloc]
|
|
|
|
initWithObjectFunction: announce_new_connection]
|
|
|
|
autorelease]
|
|
|
|
name: ConnectionWasCreatedNotification
|
|
|
|
object: nil];
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
/* Create an AppellationObject */
|
|
|
|
a1 = [[AppellationObject alloc] init];
|
1995-04-05 20:34:40 +00:00
|
|
|
sprintf(namebuf, "%d", (int)getpid());
|
1996-03-06 14:47:46 +00:00
|
|
|
[a1 setAppellation: namebuf];
|
1994-11-04 16:29:24 +00:00
|
|
|
printf("This client has appellation %s\n", [a1 appellation]);
|
|
|
|
|
|
|
|
/* Let the server know about object a1. */
|
1996-03-06 14:47:46 +00:00
|
|
|
[server addRemoteObject: a1];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Get the server's array of all other AppellationObject's */
|
|
|
|
remote_array = [server array];
|
|
|
|
|
1996-03-06 14:47:46 +00:00
|
|
|
/* Print all the appellations; this will involve making connections
|
|
|
|
to the other clients of the server. */
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
const char *s;
|
1995-01-13 17:52:53 +00:00
|
|
|
id a2; /* appellation object from server's list */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
count = [remote_array count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
1996-03-06 14:47:46 +00:00
|
|
|
a2 = [remote_array objectAtIndex: i];
|
1995-01-13 17:52:53 +00:00
|
|
|
s = [a2 appellation];
|
1996-03-06 14:47:46 +00:00
|
|
|
printf(">>>Server knows about client with appellation %s<<<\n", s);
|
1995-01-13 17:52:53 +00:00
|
|
|
if ([a2 isProxy])
|
|
|
|
(*objc_free)((void*)s);
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run, exiting as soon as there are 15 seconds with no requests */
|
1996-03-06 14:47:46 +00:00
|
|
|
[[server connectionForProxy] runConnectionWithTimeout: -1];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Clean up, to let the server know we're going away */
|
1995-06-29 00:45:55 +00:00
|
|
|
[[server connectionForProxy] invalidate];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|