Binding the socket

  • Thread starter Prigozhin Roman
  • 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
 
B

BMermuys

Hi,
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
 

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