System.Net.Sockets - How to set local port

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

is It possible to connect to remote server, port setting local ip and port with .NET Framework
I need to connect to remote server with specified local port. Can I do it

Th
Marc
 
Call the Socket.Bind() method with the local port & address information.

IPEndPoint remoteendpoint = new IPEndPoint(address, port);
IPEndPoint localendpoint = new IPEndPoint(address, port);

Socket tempSocket = new Socket(endpoint.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
tempSocket.Bind(localendpoint);
tempSocket.Connect(endpoint);

http://bill.atwill.com/
 
Back
Top