mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
(announce_new_connection): New function.
(main): Register it for notifications. Run the connection forever, instead of on a 15 second timeout. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1077 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
961ca24740
commit
a601567d41
1 changed files with 27 additions and 6 deletions
|
@ -1,5 +1,17 @@
|
|||
#include "second-client.h"
|
||||
#include <objects/String.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -12,19 +24,28 @@ int main(int argc, char *argv[])
|
|||
server = [Connection rootProxyAtName:@"secondserver"];
|
||||
printf("Found server.\n");
|
||||
|
||||
[NotificationDispatcher
|
||||
addObserver: nil
|
||||
invocation: [[[ObjectFunctionInvocation alloc]
|
||||
initWithObjectFunction: announce_new_connection]
|
||||
autorelease]
|
||||
name: ConnectionWasCreatedNotification
|
||||
object: nil];
|
||||
|
||||
/* Create an AppellationObject */
|
||||
a1 = [[AppellationObject alloc] init];
|
||||
sprintf(namebuf, "%d", (int)getpid());
|
||||
[a1 setAppellation:namebuf];
|
||||
[a1 setAppellation: namebuf];
|
||||
printf("This client has appellation %s\n", [a1 appellation]);
|
||||
|
||||
/* Let the server know about object a1. */
|
||||
[server addRemoteObject:a1];
|
||||
[server addRemoteObject: a1];
|
||||
|
||||
/* Get the server's array of all other AppellationObject's */
|
||||
remote_array = [server array];
|
||||
|
||||
/* Print all the appellations */
|
||||
/* Print all the appellations; this will involve making connections
|
||||
to the other clients of the server. */
|
||||
{
|
||||
int i, count;
|
||||
const char *s;
|
||||
|
@ -33,16 +54,16 @@ int main(int argc, char *argv[])
|
|||
count = [remote_array count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
a2 = [remote_array objectAtIndex:i];
|
||||
a2 = [remote_array objectAtIndex: i];
|
||||
s = [a2 appellation];
|
||||
printf("Server knows about client with appellation %s\n", s);
|
||||
printf(">>>Server knows about client with appellation %s<<<\n", s);
|
||||
if ([a2 isProxy])
|
||||
(*objc_free)((void*)s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Run, exiting as soon as there are 15 seconds with no requests */
|
||||
[[server connectionForProxy] runConnectionWithTimeout:15000];
|
||||
[[server connectionForProxy] runConnectionWithTimeout: -1];
|
||||
|
||||
/* Clean up, to let the server know we're going away */
|
||||
[[server connectionForProxy] invalidate];
|
||||
|
|
Loading…
Reference in a new issue