Multiprocessing via sockets

James Seymour jseymour at medar.com
Tue Mar 19 04:04:59 AEST 1991


In article <1991Mar15.101603.13968 at thunder.mcrcim.mcgill.edu> mouse at thunder.mcrcim.mcgill.edu (der Mouse) writes:
>In article <1991Mar13.053500.17782 at neon.Stanford.EDU>, sidana at neon.Stanford.EDU (Ashmeet S Sidana) writes:
>> In article <4306 at skye.ed.ac.uk> rbs at bute.ed.aiai (Robert Scott) writes:
>>> I want to generalise the system.  I want an unlimited number of
>>> machine to be able to communicate.  I can see that on each machine I
>>> need to create an array of sockets of length N (the number of
>>> machines) so that each machine can talk directly to any other.
>>
>> If your communication requirements are not too high then you could
>> just communicate through one socket (with everybody listening),
>> whereby the first byte would indicate which machine the message was
>> for (assuming < 255 machines)
>
>Um, just how does one do this?  A socket can be connected to at most
>one peer.
>

If I understand the original question correctly, here's how ya do it (it's
the way the so-called "super-daemon" works): In brief: 1) Create a daemon
that listens on a "well-known" port.  2) When a connection is made, spawn
a child (passing it the new socket fd) and let the child do the dirty work.
3) After spawning the child, go back and accept any more connections (if
any).  You can do the standard verification stuff in the child if you want
(you know, the "peer" stuff).  For details on this and other interesting IPC
related subjects, get the book "UNIX Network Programming", written by
Stevens and published by Prentice Hall.  As an adjunct to this book, I also
recommend "Advanced UNIX Programming", written by Rochkind and also published
by P.H.  [No, I don't work for the publisher :-).]  Both books are clearly
written and chock full of great example code.  The code in the examples in
the Stevens book is also available somewhere on the net (someone else here
picked it up within the last couple of weeks).

If I didn't understand the question correctly, I apologize in advance for
the (useless?) reply.

-- 
Jim Seymour				| Medar, Inc.
...!uunet!medar!jseymour		| 38700 Grand River Ave.
jseymour at medar.com			| Farmington Hills, MI. 48331
CIS: 72730,1166  GEnie: jseymour	| FAX: (313)477-8897



More information about the Comp.unix.internals mailing list