1994-11-04 16:29:24 +00:00
|
|
|
#include "second-client.h"
|
1997-01-12 19:28:07 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1996-04-17 18:40:03 +00:00
|
|
|
#include <gnustep/base/Notification.h>
|
|
|
|
#include <gnustep/base/Invocation.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
#include <Foundation/NSRunLoop.h>
|
1996-03-19 00:59:51 +00:00
|
|
|
#include <Foundation/NSDate.h>
|
1996-03-27 01:29:45 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1996-03-06 14:47:46 +00:00
|
|
|
|
|
|
|
id announce_new_connection (id notification)
|
|
|
|
{
|
|
|
|
#if 0
|
1996-03-19 00:59:51 +00:00
|
|
|
id connection = [notification object];
|
1996-03-06 14:47:46 +00:00
|
|
|
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[])
|
|
|
|
{
|
1996-07-15 18:41:44 +00:00
|
|
|
static id server;
|
1994-11-04 16:29:24 +00:00
|
|
|
id a1;
|
|
|
|
id remote_array;
|
|
|
|
char namebuf[16];
|
|
|
|
|
|
|
|
printf("Looking up server object on localhost with name `secondserver'\n");
|
1996-03-07 18:15:50 +00:00
|
|
|
if (argc > 1)
|
1997-01-12 19:28:07 +00:00
|
|
|
server = [Connection rootProxyAtName:
|
|
|
|
[NSString stringWithCString: argv[1]]];
|
1996-03-07 18:15:50 +00:00
|
|
|
else
|
|
|
|
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
|
1996-03-07 18:15:50 +00:00
|
|
|
addInvocation: [[ObjectFunctionInvocation alloc]
|
|
|
|
initWithObjectFunction: announce_new_connection]
|
1996-03-06 14:47:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-09-25 13:44:33 +00:00
|
|
|
/* Cause an exception in the server, and watch it return to us. */
|
1996-03-27 01:29:45 +00:00
|
|
|
NS_DURING
|
|
|
|
{
|
1996-07-15 18:41:44 +00:00
|
|
|
[remote_array objectAtIndex: 99];
|
1996-03-27 01:29:45 +00:00
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
1996-09-25 13:44:33 +00:00
|
|
|
printf("Exceptions are working; caught exception:\n"
|
|
|
|
"NAME: %s\n"
|
|
|
|
"REASON: %s\n",
|
|
|
|
[[localException name] cStringNoCopy],
|
|
|
|
[[localException reason] cStringNoCopy]);
|
1996-09-24 17:13:05 +00:00
|
|
|
[localException release];
|
1996-03-27 01:29:45 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
1996-03-19 00:59:51 +00:00
|
|
|
/* Run, exiting as soon as there are 30 minutes with no requests */
|
1997-09-01 21:59:51 +00:00
|
|
|
[NSRunLoop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 30 * 60]];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-03-19 00:59:51 +00:00
|
|
|
/* Clean up, to let the server know we're going away; (although
|
|
|
|
this isn't strictly necessary because the remote port will
|
|
|
|
detect that the connection has been severed). */
|
1995-06-29 00:45:55 +00:00
|
|
|
[[server connectionForProxy] invalidate];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|