Binding the socket

  • Thread starter Thread starter Prigozhin Roman
  • Start date Start date
P

Prigozhin Roman

I have 2 network cards in the machine and I'm running C# programm which connects to the
remote FTP server via socket here is the code :

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

IPEndPoint ep = new IPEndPoint(Dns.Resolve(remoteHost).AddressList[0], remotePort);

try
{
clientSocket.Connect(ep);
}
catch(Exception)
{
throw new IOException("Couldn't connect to remote server");
}

The problem is that I want my connection to go trhough specific card. Because if it( program ) picks the card
it self it goes through other sub network and slows down the connection.
Is there any whay to specify source ip of the packet I'm sending. In other words bind the socket to the specific
IP ( one of the two network cards I have )

Thanks
Roman
 
Hi,
news:e1WAx8qvDHA.3116@TK2MSFTNGP11.phx.gbl...
I have 2 network cards in the machine and I'm running C# programm which connects to the
remote FTP server via socket here is the code :
clientSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

IPEndPoint ep = new IPEndPoint(Dns.Resolve(remoteHost).AddressList[0], remotePort);

try
{
clientSocket.Connect(ep);
}
catch(Exception)
{
throw new IOException("Couldn't connect to remote server");
}
The problem is that I want my connection to go trhough specific card.
Because if it( program ) picks the card
it self it goes through other sub network and slows down the connection.
Is there any whay to specify source ip of the packet I'm sending. In other
words bind the socket to the >specific IP ( one of the two network cards I
have )

You almost gave the answer yourself. A socket has a Bind method. It takes
one parameter: an endpoint representing the local addr/port pair.

For the local port, you may choose 0 which will use a free port between 1024
and 50000.

HTH,
Greetings
 
Back
Top