Re: how to allow read/write socket only from localhost?
- From: Frank Fredstone <none@xxxxxx>
- Date: Fri, 11 Aug 2006 09:15:46 -0700
Gordon Beaton <n.o.t@xxxxxxxxx> writes:
On Thu, 10 Aug 2006 16:17:23 -0700, Frank Fredstone wrote:
I want to close a socket if the other side is not on the local
machine, how can I do that?
InetAddress.getHostname() is not "localhost" sometimes, if the
client connects to "localhost". For example, sometimes getHostname()
returns "127.0.0.1".
If it's a server doing this, then it's easier to simply prevent
non-local clients from connecting in the first place.
Just specify the localhost address when you create the ServerSocket.
Connection attempts on other interfaces will be refused by the
operating system, so you never have to deal with them in your
application.
Thank you! It appears to do what you say, but I don't understand the
javadoc:
"The bindAddr argument can be used on a multi-homed host for a
ServerSocket that will only accept connect requests to one of its
addresses."
Is that saying the client must have a local address that is the same
as was given to the ServerSocket constructor on the server?
.
- Follow-Ups:
- Re: how to allow read/write socket only from localhost?
- From: Gordon Beaton
- Re: how to allow read/write socket only from localhost?
- References:
- how to allow read/write socket only from localhost?
- From: Frank Fredstone
- Re: how to allow read/write socket only from localhost?
- From: Gordon Beaton
- how to allow read/write socket only from localhost?
- Prev by Date: Re: how to transform html file to image?
- Next by Date: Re: Eclipse + WTP Help
- Previous by thread: Re: how to allow read/write socket only from localhost?
- Next by thread: Re: how to allow read/write socket only from localhost?
- Index(es):
Relevant Pages
|