Hey Dan, thanks. This is fantastic.
On Tue, 14 Dec 2004 19:56:25 +0000, Dan Creswell <email@hidden> wrote:
> Hmmm, something like this came up recently under the subject:
> ServerSocket on Mac OS X. Here was the conclusion of the conversation:
>
> Hello again,
>
> Thank you very much for all your help. The problem was indeed that java
> used ipv6 instead of ipv4. To solve it, it sufficed to add the line:
>
> System.setProperty("java.net.preferIPv4Stack","true");
>
> Thanks
> Frank
>
> And here's the original question:
>
> All I want to do at the moment is figuring out how to determine whether a
> port is in use. Knowing java from different systems / programming languages
> this should be pretty straightforward. The snippet:
>
> boolean bInUse;
> try{
> ServerSocket oSocket = new ServerSocket();
> oSocket.bind(new InetSocketAddress("host",nPort));
> bInUse = false;
> oSocket.close();
> }
> catch(BindException oBind)
> {
> bInUse = true;
> }
>
> should give me the answer right away. The problem though is that I have a
> C++ application sitting on the port first. And still the snippet tells me
> that this port would not be in use.
>
> Intrigued by that I wrote another small example accepting a connection to
> this Java program. Here the outcome:
>
> 1. start C++ application on port X --> success
> 2. start Java application on port X --> success
> 3. telnet to localhost port X --> java responds (and shuts down)
> 4. telnet to localhost port X --> C++ responds
>
> Now I'm completely clueless. I mean the C++ application will not bind to the
> port if Java is already on the port, so what is going on here.
>
> Jesse Wilson wrote:
> >
> > My PowerBook lets me bind to the same port twice using NIO. The
> > following code throws an IOException under Windows and Linux, but not
> > under Mac OS X:
> >
> > *public* *void* bindTwice(*int* port) *throws* IOException {
> > InetSocketAddress listenAddress = *new* InetSocketAddress(port);
> >
> > ServerSocketChannel firstChannel = ServerSocketChannel.open();
> > ServerSocket firstSocket = firstChannel.socket();
> > firstSocket.bind(listenAddress);
> >
> > ServerSocketChannel secondChannel = ServerSocketChannel.open();
> > ServerSocket secondSocket = secondChannel.socket();
> > secondSocket.bind(listenAddress); }
> >
> > It wouldn't be too big a deal but I want my application to fail if it
> > can't bind! One horrible problem that has come up in my tests is
> > this: 1. Bind to port X as server. 2. Connect to self on port X as
> > client. Now the client has fully connected but server has not
> > received anything! Another server process that has binded to the same
> > port is receiving the data instead.
> >
> > Is this a bug in the Mac JVM?
> >
> > Any information on this problem will be appreciated, thanks!
> >
> > Cheers, Jesse Wilson
> >
> >
> > ------------------------------------------------------------------------
> >
> >
> > _______________________________________________ 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
>
> ___________________________________________________________
> $0 Web Hosting with up to 120MB web space, 1000 MB Transfer
> 10 Personalized POP and Web E-mail Accounts, and much more.
> Signup at www.doteasy.com
>
>
_______________________________________________
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