Re: Beginner's problem



Amit <bubuman_98 yahoo com> wrote:
> Hello,
> 
> Please pardon my ignorance, as I am just starting up
> with ORBit. I will really appreciate if anyone can
> help me with the following :
> 
> I have created the server and created the client. I
> want to start server programmatcally (in stead of
> typing). Is there an example somewher , which I can
> refer to? Also, how can I use the client from an
> external program ?

You need to use fork() and exec() to start your server from the client.

Basic pseudo-C-code (off the top of my head, messy as hell, intended as a
guide only, don't copy and paste this code, research it and learn what
you're really doing!):

/* make unnamed pipes for communication between parent and child */
int fds[2];
pipe(fds);
childpid = fork();
if (childpid > 0) {
	/* parent */
	char iorbuf[4097];
	close(fds[1]);
	/* read the IOR from the child */
	read(fds[0], 4096, iorbuf);
} else if (childpid == 0) {
	/* child */
	close(fds[0]);
	/* make stdout go to parent */
	dup2(fds[1], 1);
	/* exec your server, which writes the IOR to stdout */
	char *args[2] = {"/path/to/your/server", NULL};
	exec("/path/to/your/server", args);
	/* NOTREACHED */
	fprintf(stderr, "Where does your server *really* live?");
} else {
	/* error */
}

Or something like that. Read man pages for pipe(), fork(), exec(), and
probably dup2(), read() and write() as well.

An alternative is for the child to simply create a server object and write
the IOR to the pipe, rather than starting a seperate server program.
-- 
Sam Couter          |   Internet Engineer   |   http://www.topic.com.au/
sam topic com au    |   tSA Consulting      |
OpenPGP key available on key servers
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C
-- 
Sam Couter          |   Internet Engineer   |   http://www.topic.com.au/
sam topic com au    |   tSA Consulting      |
OpenPGP key available on key servers
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C

Attachment: pgpbmeHCdPt2d.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]