PC Review


Reply
Thread Tools Rate Thread

Connect to Internet-IP via a specific gateway

 
 
Matthias Springer
Guest
Posts: n/a
 
      17th Aug 2009
Hi,

I'm planning to write a small .NET application which connects to a
server IP in the internet. As I have two internet connections there are
two possible ways to connect to the server - via IP1 and IP2.

Is there any possibility of choosing which gateway (router IP) to use
when connecting to the internet IP?

I'm running a Windows XP system and my program always chooses the
internet connection which is defined as the standard gateway.

Thanks.
 
Reply With Quote
 
 
 
 
Bert Hyman
Guest
Posts: n/a
 
      17th Aug 2009
In news:h6bv74$7ep$(E-Mail Removed) Matthias Springer
<(E-Mail Removed)> wrote:

> Is there any possibility of choosing which gateway (router IP) to use
> when connecting to the internet IP?


In C, you'd use the "bind" function to attach your socket to a specific
local IP address (and port if you want or need to) before doing the
connect.

I'd hope that dotNet has a way to perform that operation.

--
Bert Hyman St. Paul, MN (E-Mail Removed)
 
Reply With Quote
 
Bert Hyman
Guest
Posts: n/a
 
      17th Aug 2009
In news:Xns9C6A7A9B6A7B6VeebleFetzer@207.46.248.16 Bert Hyman
<(E-Mail Removed)> wrote:

> I'd hope that dotNet has a way to perform that operation.


Ah... There it is:

System.Net.Sockets.Socket.Bind(EndPoint local_ep)

--
Bert Hyman St. Paul, MN (E-Mail Removed)
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      17th Aug 2009
On Mon, 17 Aug 2009 10:03:09 -0700, Bert Hyman <(E-Mail Removed)> wrote:

> In news:h6bv74$7ep$(E-Mail Removed) Matthias Springer
> <(E-Mail Removed)> wrote:
>
>> Is there any possibility of choosing which gateway (router IP) to use
>> when connecting to the internet IP?

>
> In C, you'd use the "bind" function to attach your socket to a specific
> local IP address (and port if you want or need to) before doing the
> connect.
>
> I'd hope that dotNet has a way to perform that operation.


The binding of a socket doesn't determine the route the data takes; the
network stack with its routing information does that. If you are
connecting to an Internet IP address, and you have more more than one
network adapter connected to more than one gateway that can reach that
Internet IP address, then barring some explicit routing configuration, the
network stack will pick the one it thinks is best at that moment.

..NET has a Socket class that very closely mirrors the BSD-style Winsock
API, including a Bind() method. But that's only going to affect the IP
address used by the remote endpoint to reply, just as it would in Winsock
or using sockets on a Unix/Linux system.

That said, the original post is not very clear about what goal it is the
person is actually trying to achieve. It's possible that binding to a
specific IP address rather than 0.0.0.0 (IPAddress.Any) would suit his
needs, in spite of what the post appears to say.

If not, then if I recall correctly, one can provide routing configuration
via WMI, which is accessible through .NET. I don't have any of the
specifics, but that would be the way to do it if he really does need to
force a specific routing for the traffic.

Pete
 
Reply With Quote
 
Bert Hyman
Guest
Posts: n/a
 
      17th Aug 2009
In news(E-Mail Removed) "Peter Duniho"
<(E-Mail Removed)> wrote:

> The binding of a socket doesn't determine the route the data takes;


It doesn't affect the "route" once the packet leaves the PC, but allows you
to attach your socket to a specific interface, if your machine has more
than one.

--
Bert Hyman St. Paul, MN (E-Mail Removed)
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      17th Aug 2009
On Mon, 17 Aug 2009 10:49:26 -0700, Bert Hyman <(E-Mail Removed)> wrote:

> In news(E-Mail Removed) "Peter Duniho"
> <(E-Mail Removed)> wrote:
>
>> The binding of a socket doesn't determine the route the data takes;

>
> It doesn't affect the "route" once the packet leaves the PC, but allows
> you
> to attach your socket to a specific interface, if your machine has more
> than one.


No, not really. The remote endpoint will be guaranteed to see your
endpoint as that IP address, but there's no guarantee about how data from
your endpoint will get to the remote endpoint, even when the socket is
bound to a specific IP address.

Here are a few topics found scattered around the Internet that discuss
this very issue (mostly in terms of people complaining that when they use
bind(), the network traffic is still routed over a different adapter than
then one they wanted):

http://social.msdn.microsoft.com/For...5-1e1bf810eff4
http://mail.python.org/pipermail/pyt...ch/653002.html
http://lists.apple.com/archives/darw.../msg00244.html
http://www.developerweb.net/forum/showthread.php?t=3357

You'll note that the issue is a fundamental network implementation issue,
not unique to .NET at all. It exists across different frameworks and even
OS platforms.

Pete
 
Reply With Quote
 
Bert Hyman
Guest
Posts: n/a
 
      17th Aug 2009
In news(E-Mail Removed) "Peter Duniho"
<(E-Mail Removed)> wrote:

> On Mon, 17 Aug 2009 10:49:26 -0700, Bert Hyman <(E-Mail Removed)>
> wrote:
>
>> In news(E-Mail Removed) "Peter Duniho"
>> <(E-Mail Removed)> wrote:
>>
>>> The binding of a socket doesn't determine the route the data takes;

>>
>> It doesn't affect the "route" once the packet leaves the PC, but
>> allows you to attach your socket to a specific interface, if your
>> machine has more than one.

>
> No, not really. The remote endpoint will be guaranteed to see your
> endpoint as that IP address, but there's no guarantee about how data
> from your endpoint will get to the remote endpoint, even when the
> socket is bound to a specific IP address.


Nowhere do I mention the remote endpoint or the route your packet will
take to a remote endpoint, and the bind function doesn't either.

If your machine has multiple interfaces, each with a different IP
address, the bind function allows you to attach your socket to a
specific interface before performing a listen or connect.

--
Bert Hyman St. Paul, MN (E-Mail Removed)
 
Reply With Quote
 
Matthias Springer
Guest
Posts: n/a
 
      17th Aug 2009
Thank you for your fast answers.

> If your machine has multiple interfaces, each with a different IP
> address, the bind function allows you to attach your socket to a
> specific interface before performing a listen or connect.


My machine has only one network interface. The computer is connected to
a switch and two routers (one for each internet connection) are
connected to the switch.
By setting the standard gateway to one of the router's IP on my machine
I can force Windows to send my packages through a specific internet
connection.

My .NET program should be able to send packages through a specific
internet connection (router, standard gateway) without changing the
standard gateway of the network adapter.

Therefore I want to send packages to one single IP address through both
internet connections simultaneously. I'm not familiar with routing but
this could perhaps make things more difficult.

It might not be relevant, but my goal is to write an application which
can balance network load on multiple internet connections.

Thanks.
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      17th Aug 2009
On Mon, 17 Aug 2009 11:21:44 -0700, Bert Hyman <(E-Mail Removed)> wrote:

> In news(E-Mail Removed) "Peter Duniho"
> <(E-Mail Removed)> wrote:
>
>> On Mon, 17 Aug 2009 10:49:26 -0700, Bert Hyman <(E-Mail Removed)>
>> wrote:
>>
>>> In news(E-Mail Removed) "Peter Duniho"
>>> <(E-Mail Removed)> wrote:
>>>
>>>> The binding of a socket doesn't determine the route the data takes;
>>>
>>> It doesn't affect the "route" once the packet leaves the PC, but
>>> allows you to attach your socket to a specific interface, if your
>>> machine has more than one.

>>
>> No, not really. The remote endpoint will be guaranteed to see your
>> endpoint as that IP address, but there's no guarantee about how data
>> from your endpoint will get to the remote endpoint, even when the
>> socket is bound to a specific IP address.

>
> Nowhere do I mention the remote endpoint or the route your packet will
> take to a remote endpoint, and the bind function doesn't either.


Whatever. The remote endpoint is implied in _any_ discussion of
networking, and you even quoted your own post where you "mentioned" the
"route". See above. I don't see how you can say that you didn't mention
it, given that it's there in plain view in your own previous post.

> If your machine has multiple interfaces, each with a different IP
> address, the bind function allows you to attach your socket to a
> specific interface before performing a listen or connect.


Unfortunately, the word "attach" is at best a synonym for "bind", and at
worst has no precise technical meaning. Either way, saying that the "bind
function allows you to attach your socket" is either meaningless,
irrelevant, or incorrect. Take your pick.

The OP asked for control over which adapter is _used_, not which IP
address to which the socket is bound, so it's reasonable to assume you
were trying to answer the former question, not the latter. But your
answer doesn't address the former question, thus my reply.

If you _aren't_ trying to answer the question about how to control which
adapter is actually _used_, then you aren't trying to answer the question
that was asked. And that seems a little pointless.

Pete
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      17th Aug 2009
On Mon, 17 Aug 2009 11:51:18 -0700, Matthias Springer
<(E-Mail Removed)> wrote:

> [...]
> My .NET program should be able to send packages through a specific
> internet connection (router, standard gateway) without changing the
> standard gateway of the network adapter.
>
> Therefore I want to send packages to one single IP address through both
> internet connections simultaneously. I'm not familiar with routing but
> this could perhaps make things more difficult.
>
> It might not be relevant, but my goal is to write an application which
> can balance network load on multiple internet connections.


One might expect the network stack to deal with that on its own, though I
admit that normal desktop OSs, including Windows, may well not have that
feature. In any case, I don't believe you can control this sort of thing
programmatically with a socket, and for sure the Socket.Bind() method
isn't going to be helpful at all.

If you have control over both endpoints, your best strategy is probably
simply to create multiple connections, multiplexing the data yourself, and
hoping that the underlying network structure will correctly use both
available network connections for routing. I don't know whether it would,
but it's worth a try. If you can't even get it to work with multiple
sockets (for a test, don't even bother trying to keep the data streams
coherent...just send random data simultaneously over two connections and
see what kind of throughput you get), then I see very little hope in
convincing the network stack to multiplex a single socket connection on
your behalf.

And of course, if you don't have control over the remote endpoint, then
you're going to be entirely dependent on whatever features your platform
provides, such as that may be. There's not a configuration thing you can
adjust in the Socket class that would affect that, nor do I think you want
to be messing around with the routing on a real-time basis.

Pete
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect to Internet Gateway =?Utf-8?B?QW5kcmV3?= Windows XP Internet Explorer 1 9th Jun 2007 12:55 AM
Internet Gateway on ICS will not connect from client =?Utf-8?B?UGF1bGlv?= Windows XP Networking 0 9th Oct 2006 11:05 PM
Cannot connect to Internet with ADSL Gateway - PLEASE HELP! =?Utf-8?B?ZmVycmlz?= Windows XP Networking 3 23rd Nov 2004 03:13 AM
Can't connect to the Internet via Gateway Christof Windows Networking 2 15th Feb 2004 01:19 PM
gateway won't connect to internet? cory Windows XP Networking 1 4th Jan 2004 10:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:00 AM.