un***@web.de (Horst Walter) wrote in message news:<53**************************@posting.google. com>...
What is wrong here?
IPAddress ipAddress = IPAddress.Parse("10.10.20.1");
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, this.port);
this.tcpClient = new TcpClient(ipEndPoint); // PROBLEM HERE
=> Exception: "The requested address is not valid in its context"
This works:
this.tcpClient = new TcpClient("10.10.20.1", this.port);
Horst -
You are mixing apples with oranges. The TcpClient constructor that
uses the IPEndPoint defines a local endpoint for the socket to bind
to, while the constructor that uses the string defines a remote
endpoint for the socket to connect to. Thus, the first constructor is
looking to bind the socket to the local IP address and port specified
in the IPEndPoint object. Since you gave it a remote IP address it
couldn't perform the task and threw the Exception.
If you want to connect to a remote endpoint using an IPEndPoint
object, try using the Socket object. This allows you to use an
EndPoint, and shouldn't try the DNS lookup of the IP address. This
would look something like this:
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("10.10.20.1",
this.port);
sock.Connect(ipep);
NetworkStream ns = new NetworkStream(sock);
Hope this helps solve your problem.
Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html