473,509 Members | 2,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TcpClient Exception: "The requested address is not valid in its context"

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);

However, the latter is somehow slow, because it seems that in this
case a DNS resolution takes place. This is exactly what I'd like to
avoid.

Any ideas?
Regards HW
Nov 15 '05 #1
5 72129

This may be cause the IP is not a valid IP on your computer, or maybe the
port is binded to another application.

If you dont really need to especify the IP then create the IPEndPoint with a
0:
IPEndPoint ipEndPoint = new IPEndPoint( 0, this.port);

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Horst Walter" <un***@web.de> wrote in message
news:53**************************@posting.google.c om...
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);

However, the latter is somehow slow, because it seems that in this
case a DNS resolution takes place. This is exactly what I'd like to
avoid.

Any ideas?
Regards HW

Nov 15 '05 #2
Is "10.10.20.1" the IP of your own machine?
Just guessing. Maybe the second overload of TcpClientConstructor can handle
that, but an IP on your own machine doesn't qualify as an "EndPoint".

"Horst Walter" <un***@web.de> wrote in message
news:53**************************@posting.google.c om...
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);

However, the latter is somehow slow, because it seems that in this
case a DNS resolution takes place. This is exactly what I'd like to
avoid.

Any ideas?
Regards HW

Nov 15 '05 #3
Firstly, thanks a lot for your help!

However, the solution still is not clear:

"10.10.20.1" in my case is a valid IP and NOT the IP of the computer
itself (where the prg. runs).

Furthermore this works (SAME PORT /IP):
this.tcpClient = new TcpClient("10.10.20.1", this.port);

So I do not believe it is some kind of general network problem.....

Regards
KB
"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> wrote in message news:<bq**********@sulawesi-fi.lerc.nasa.gov>...
Is "10.10.20.1" the IP of your own machine?
Just guessing. Maybe the second overload of TcpClientConstructor can handle
that, but an IP on your own machine doesn't qualify as an "EndPoint".

"Horst Walter" <un***@web.de> wrote in message
news:53**************************@posting.google.c om...
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);

However, the latter is somehow slow, because it seems that in this
case a DNS resolution takes place. This is exactly what I'd like to
avoid.

Any ideas?
Regards HW

Nov 15 '05 #4
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
Nov 15 '05 #5
Thanks a lot!
HW

ri*******@juno.com (Rich Blum) wrote in message news:<cc**************************@posting.google. com>...
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

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7824
by: Aaron | last post by:
IIS 5.0 is throwing out "The requested resource is in use." for any site that uses ASP - HTML is executing fine. I have tried re-installing scripting, latest MDAC, and all my hotfixes are up to...
8
19137
by: H. S. | last post by:
I am getting this error if I try to compile the file demarcated below. What I am missing here? I am using g++ (GCC) 3.3.5 (Debian 1:3.3.5-8). {tp2}> g++ -ansi -g -Wall tp2.cc -o tp2 tp2.cc: In...
24
2709
by: jrefactors | last post by:
I have an upload file operation in the web application. UploadForm.jsp is the form, and UploadAction.jsp is the form processing. The web server is Websphere. //UploadForm.jsp <FORM...
7
9512
by: Søren Dreijer | last post by:
Hi, I have a mixed C#, managed C++ and unmanaged C++ project. The managed class calls a method which exists in an unmanaged singleton class. During the entire lifetime of the application, this...
0
3088
by: keikoo | last post by:
Hi, I need some help with this control. There's a windows form with a axwebbrowser control inside, so users can navigate to a page and it's necessary to keep the session, because, users will...
3
30494
by: martin | last post by:
Hello, Could someone here please explain the reason for the error in the subject (the full error below) I dont get this everytime and i've never gotten while debugging. The code (also below)...
1
3570
by: =?Utf-8?B?c3DDr3LDtg==?= | last post by:
I'm having a problem with MS outlook. Neither of my email accounts were working, so I reinstalled hoping that, that would fix the problem - unfortunatly it didn't. When I go to create a new...
4
10421
by: channau2 | last post by:
HI, i am trying to create a simple UDP client application on the windows mobile using c# to send messages as data packets to a desktop pc. I am getting this error when deploy the application on...
1
1901
by: Arash Khatibi | last post by:
I repeatedly encounter "the requested URL not supported" or "the requested URL could not be retrieved" on many websites that I formerly could get access to. please help me solve this problem. thanks
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.