From owner-freebsd-hackers Mon May 10 11:55:11 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from mail-out2.apple.com (mail-out2.apple.com [17.254.0.51]) by hub.freebsd.org (Postfix) with ESMTP id 8668615C9B for ; Mon, 10 May 1999 11:55:04 -0700 (PDT) (envelope-from justin@rhapture.apple.com) Received: from mailgate2.apple.com ([17.129.100.225]) by mail-out2.apple.com (8.8.5/8.8.5) with ESMTP id LAA59450 for ; Mon, 10 May 1999 11:39:11 -0700 Received: from scv3.apple.com (scv3.apple.com) by mailgate2.apple.com (mailgate2.apple.com- SMTPRS 2.0.15) with ESMTP id ; Mon, 10 May 1999 11:39:00 -0700 Received: from rhapture.apple.com (rhapture.apple.com [17.202.40.59]) by scv3.apple.com (8.9.3/8.9.3) with ESMTP id LAA16090; Mon, 10 May 1999 11:38:59 -0700 Received: by rhapture.apple.com (8.9.1/8.9.1) id LAA00711; Mon, 10 May 1999 11:38:53 -0700 (PDT) Message-Id: <199905101838.LAA00711@rhapture.apple.com> To: Zhihui Zhang Subject: Re: Sockets and SYSTEM V message queue Cc: freebsd-hackers@freebsd.org Date: Mon, 10 May 1999 11:38:50 -0700 From: "Justin C. Walker" Reply-To: justin@apple.com X-Mailer: by Apple MailViewer (2.105.dev) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > From: Zhihui Zhang > Date: 1999-05-10 11:11:45 -0700 > To: freebsd-hackers@FreeBSD.ORG > Subject: Sockets and SYSTEM V message queue > Delivered-to: freebsd-hackers@freebsd.org > X-Loop: FreeBSD.ORG > > > My impression is that whenever you create a socket, you bind to some IP > address. If you creates two sockets on the same machine, these two > sockets will bind to the same IP address (assuming that the machine has > only one NIC). When these two sockets communicate with each other, the OS > should be smart enough to figure out that they associated with the same IP > address and therefore do not actually send packets out to the network. > > If this is the case, why do we bind a socket to an IP address. I mean, > the sockets should be able to be used alone. If they have to be bound to > an IP address to be used, why do not we use message queue of SYS V? If > so, which mechanism is better - message queue or standalone socket? Typically, the "server" (receiver) end of the initiated connection will bind either to INADDR_ANY, with a well-known port. If the server is really concerned with networking details, it might determine the addresses and interfaces on the system, and bind separately to each. The client (initiator) will generally always bind to INADDR_ANY, and let the system choose a port. One reason to use IP is that you may, in the future, want to run the two pieces on different systems. If so, you can do it without code changes. If your app is always going to run on a single system, there are better ways to implement it. Local-domain sockets is one; pipes is another (which may or may not be implemented with local-domain sockets). SysV message queues could be used as well. Don't know enough about their limitations to know whether it's a good choice, though. Also, even tho the binds are done with INADDR_ANY, at the time a connection is made, a real address is assigned. This is how IP works. Why is this a problem? Regards, Justin -- Justin C. Walker, Curmudgeon-At-Large * Institute for General Semantics | Manager, CoreOS Networking | Men are from Earth. Apple Computer, Inc. | Women are from Earth. 2 Infinite Loop | Deal with it. Cupertino, CA 95014 | *-------------------------------------*-------------------------------* To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message