Socket listener with multiple IPEndPoints???

J

Jon

I'm trying to figure out if it is possible to bind multiple IPs to the
same Socket listener. For example, when I bind my LAN IP to the
socket, Only computers on my network are able to connect to the
server. When I bind my External IP, everyone except computers on my
network can connect to the server. I'm wondering if it is possible to
bind both IP addresses to the same Socket when listening for
connections. Here is some code to help illustrate my question:

--------------------------------
Socket listener = new Socket( AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp );

listener.Bind( new IPEndPoint( localAddress[0], portNum ) );
listener.Listen(5);

listener.BeginAccept( new AsyncCallback( this.OnConnectRequest ),
listener );


-------------------------


Any suggestions are welcomed. All I really want is to be able to
"Listen" from 2 different IPs, without having to create a totally new
socket. I might be doing this completely wrong, since I am totally
new to sockets.

Thanks in advance,
Jon
 
M

Michael Bray

(e-mail address removed) (Jon) wrote in @posting.google.com:
I'm trying to figure out if it is possible to bind multiple IPs to the
same Socket listener. For example, when I bind my LAN IP to the
socket, Only computers on my network are able to connect to the
server. When I bind my External IP, everyone except computers on my
network can connect to the server. I'm wondering if it is possible to
bind both IP addresses to the same Socket when listening for
connections. Here is some code to help illustrate my question:

Instead of binding to a specific IP Address, you can bind to IPAddress.Any.

-mdb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top