[comp.sys.mac.programmer] For hippo@tardis Re: Sockets

rmh@apple.com (Rick Holzgrafe) (02/27/90)

My mailer choked on the address: hippo@tardis.computer-science.edinburg
Sorry to hippo for the late reply; sorry to the net for spending the
bandwidth.
===
You shouldn't need a well-known socket number. Well, that's a little 
severe; let's say you probably don't need a well-known socket number.
If you do, contact Apple Developer Technical Support; I wouldn't know
what to do.
 
To get along without one, do as follows. Create your listener with a socket
value of zero, as you've been doing, and let CLInit choose the real socket
number for you. When your listen completes and you create the new
connection end for the new circuit, use the same socket id. Don't destroy
the listener first - this may be your trouble. (It works for me: I accept
multiple calls and therefore never destroy the listener before accepting a
call.) Once you've successfully accepted the call, then you can safely
destroy the listener.
 
(The rest is about NBP: skip it if you're familiar with NBP.)
 
Now you don't need a well-known socket number just to get around the
problem of getting a socket number assigned. You still have the problem
of remote clients needing to know your address. This is what NBP is for.
When your listener is established and listening, register it with NBP.
This involves giving it a name and a type (e.g. name "My Favorite
Printer" and type "LaserWriter"). All instances of your widget will have
the same type (make one up) but must have different names within a given
AppleTalk zone. NBP associates the name/type with your real network
address and publishes it. Remote clients can then do NBP lookup for
objects of your type: there's a call to get the list of all such
objects in a zone, and a call to learn the real network address of an 
object in the list. (This is what the Chooser does: the user selects a
zone and an object type, and the Chooser displays the list of all such
objects in the zone.) Now the client has your real address, and can place
a call to you.
 
NBP is documented in Inside Mac volume II ("The AppleTalk Manager") and
isn't any wierder than anything else in networking. I strongly recommend
you use it rather than using a "well-known" socket id. Much of the power
of AppleTalk would be lost if everyone used well-known addresses rather
than dynamic ones.
 
Again, hope this helps.
 
P.S. Are you really in Edinburgh? A lovely place; we vacationed in Great
Britain a couple of years ago and it was a high point of our trip.

==========================================================================
Rick Holzgrafe              |    {sun,voder,nsc,mtxinu,dual}!apple!rmh
Software Engineer           | AppleLink HOLZGRAFE1          rmh@apple.com
Apple Computer, Inc.        |  "All opinions expressed are mine, and do
20525 Mariani Ave. MS: 67-B |    not necessarily represent those of my
Cupertino, CA 95014         |        employer, Apple Computer Inc."