Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bind several times to the same port in Mac OS X



Normally this is controlled by setsockopt with SO_REUSEADDR and (on some BSD-based systems, OSX included) SO_REUSEPORT.

You might use getsockopt in your C++ program to see how these options are set, e.g.

int inuse;
int result = getsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&inuse, sizeof(inuse));


I believe the winsock default lets you do multiple binds (with undefined results), while most *nix make the bind exclusive by default. Last I tested OSX requires both ADDR and PORT be set in order to reuse a UDP port (e.g. for multicast).

On Dec 14, 2004, at 4:08 PM, Jesse Wilson wrote:

Dan Creswell kindly pointed me to a similar thread on this list,
"ServerSocket on Mac OS X" which was solved by using IPv4 instead of
IPv6:
    http://lists.apple.com/archives/java-dev/2004/Dec/thrd2.html

Unfortunately NIO still allows me to bind multiple times using IPv4.
For example, I've written a simple program that binds to IPv4 port
50505 twice. Here's what netstat has to say:

slackette:jessewilson$ netstat -a
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 *.50505 *.* LISTEN
tcp4 0 0 *.50505 *.* LISTEN


This is really wacky, but I'm making progress. Does anybody else have any ideas?

Thanks in advance,
Jesse Wilson
http://publicobject.com/glazedlists/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Bind several times to the same port in Mac OS X (From: Jesse Wilson <email@hidden>)
 >Re: Bind several times to the same port in Mac OS X (From: Dan Creswell <email@hidden>)
 >Re: Bind several times to the same port in Mac OS X (From: Jesse Wilson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.