Cannot resolve IP with TcpClient

  • Thread starter Thread starter Morten Nielsen
  • Start date Start date
M

Morten Nielsen

I'm trying to connect to server via TcpClient, but gets the following error:
"This is usually a temporary error during hostname resolution and means that
the local server did not receive a response from an authorative server."

The code has been tested in a Windows Application and works fine. I can also
connect to the IP address via Pocket Internet Explorer, so connection should
be fine. I connect via GPRS (which I also have tested to be ok), but it
seems that the error is the same whether or not I have an active internet
connection.

Any idea on what could be wrong?
Code that fails:
-------------------------
TcpClient client;
try
{
client = new TcpClient("129.217.182.51",80); //This one fails
}
catch(System.Exception ex)
{
MessageBox.Show("Error connecting to server:" + ex.Message);
return;
}
-------------------------

I have also tried
IPHostEntry remoteHost = Dns.Resolve("129.217.182.51");
which creates the same error.

Any help or suggestions appreciated

Regards
/Morten Nielsen (email: http://www.iter.dk/contact.aspx )

Implementing GPS in your Pocket PC app?
http://www.iter.dk/software/PocketGpsLib
 
It looks to me like you are trying to treat the IP address as a host *name*.
DNS isn't going to be able to look that up (it converts names like
"www.microsoft.com" into IP addresses). To use an IP address, you really
want to create the TcpClient instance with the default constructor and then
tell it to connect.

client = new TcpClient();
client.Connect( IPAddress.Parse( yourstring ), portnumber );

Paul T.
 
It looks to me like you are trying to treat the IP address as a host
*name*.
DNS isn't going to be able to look that up (it converts names like
"www.microsoft.com" into IP addresses). To use an IP address, you really
want to create the TcpClient instance with the default constructor and then
tell it to connect.

client = new TcpClient();
client.Connect( IPAddress.Parse( yourstring ), portnumber );

Thanks a lot. That 'kinda' helped. Now I'm getting a completely new and way
more strange error:
A managed SocketException occured at Application::Run+0xf
An unknown, invalid, or unsupported option or level was specified in a
getsockopt or setsockopt call.

Is far as I can understand from this page:
 
It looks to me like you are trying to treat the IP address as a host
*name*.
DNS isn't going to be able to look that up (it converts names like
"www.microsoft.com" into IP addresses). To use an IP address, you really
want to create the TcpClient instance with the default constructor and then
tell it to connect.

client = new TcpClient();
client.Connect( IPAddress.Parse( yourstring ), portnumber );

Thanks a lot. That 'kinda' helped. Now I'm getting a completely new and way
more strange error (when running client.Connect(...)) :
"A managed SocketException occured at Application::Run+0xf
An unknown, invalid, or unsupported option or level was specified in a
getsockopt or setsockopt call."

Is far as I can understand from this page:
http://www.dotnet247.com/247reference/msgs/43/216044.aspx
there's something about .NET CF isn't supporting option and level (whatever
that means). The answer doesn't make much sense to me either. Can anyone
give me a pointer on what I can do -especially since I'm only using sockets
indirectly (that is TcpClient).

/Morten
 
Post the code for the routine that errors out. I've done this a bunch and
it never fails. Also, tell us where the debugger drops you when that
exception is fired.

By the way, if the server isn't listening for you on that port, you *will*
get an exception...

Paul T.
 
The code:
---------------------------------------
private void StartNTRIP2()
{
IPAddress BroadCasterIP = IPAddress.Parse("129.217.182.51");
int BroadCasterPort = 80;
TcpClient client;
client = new TcpClient();
try
{
client.Connect(BroadCasterIP,BroadCasterPort); // <== This one fails
}
catch(System.Exception ex)
{
MessageBox.Show("Error connecting to server:" + ex.Message);
return;
}
}
---------------------------------------

I have completely rewritten the code to use a socket instead. Even though
TcpClient actually is a socket connection, it works much better with a
socket instead (even through ActiveSync where I can't even get Pocket
Internet Explorer to work!!!). I liked the TcpClient approach better though.
It was much simpler an cleaner code.

But this doesn't change the fact that I just finished my prototype of
something REALLY cool. I'm gonna be rich !!! :-)

Regards
/Morten Nielsen
 
Well, I don't see anything wrong there. It's possible that some option that
the TcpClient sets by default doesn't exist on an ActiveSync connection, if
that's what you're using. That code works fine for me with network
connectivity...

Paul T.
 
Well, I don't see anything wrong there. It's possible that some option
that
the TcpClient sets by default doesn't exist on an ActiveSync connection, if
that's what you're using. That code works fine for me with network
connectivity...

As I said in the beginning, I use GPRS (modem) connection.

/Morten
 
Back
Top